I Need Help with a FUTURE DATE Script.. But I'm No Programmer

by 11 replies
14
Hey guys..

I went crazy on google earlier tryin to find a date script that will display the Thursday of the current week...

for example.. if today is Saturday, December 5, 2009... the website displays Thursday, December 10, 2009..

Is it possible.. and can anyone help a warrior out?

Hector...
#programming #date #future #programmer #script
  • Well what kind of script do you need. Do you need one programmed in JS, PHP, ASP. If you need a specific one that would be good, if not, I may be able to shoot out a php one. Not too sure how useful this script is, but everyone needs something different.
    :]

    --m4rx
  • Hi Hector, what you need will be something like this:

    $daysUntilThursday = 0;
    switch (date("l") {
    case "Wednesday": $daysUntilThursday = 1; break;
    case "Tuesday": $daysUntilThursday = 2; break;
    case "Monday": $daysUntilThursday = 3; break;
    case "Sunday": $daysUntilThursday = 4; break;
    case "Saturday": $daysUntilThursday = 5; break;
    case "Friday": $daysUntilThursday = 6; break;
    default:
    // today is Thursday
    $daysUntilThursday = 0;
    }
    $ThursdayToShow = date_add($date, new DateInterval("P" + $daysUntilThursday + "D"));
    echo "Your Thursday update is due on " + date($ThursdayToShow)

    You will need to adapt this to your needs and debug it, but I think it will get you most of the way there.

    Chris
  • That is perfect, and quite along the lines of the one I was making before 'work' but the problem is that DateInterval isn't available until 5.3, as of which I know some webhost's don't have, so Hecman104 may have some problems.

    --m4rx
  • Got It. This has no extensive testing, but should work for what you need it for.
    It need's nothing but the basics, and if you want to see it for yourself, here's a link.
    http://tylerperroux.com/portfolio/date.php


    PHP Code:
    <?php
    global  ;
    // Set Timezone
    date_default_timezone_set('UTC');

    // Explicitly set days until the next thursday
     
    0;
    switch (
    date('l')) {

        case 
    'Friday'
             = 
    6
        break;
        case 
    'Saturday'
             = 
    5
        break;
        case 
    'Sunday':     
             = 
    4
        break;
        case 
    'Monday'
             = 
    3
        break;
        case 
    'Tuesday'
             = 
    2
        break;
        case 
    'Wednesday':
             = 
    1
        break;
        default:
        
    // today is Thursday
             
    0;
        break;
    }

    // Add to the number in the current month
    // This get's it into the right week so we can have a proper date
     
    date('d') + ;

    // Is the number over 30/31
    if( > cal_days_in_month(CAL_GREGORIANdate(n), date('Y'))){

        
    // Will fix the day int. (ex. 35 > 31(dec), so 35-31= 4, thursday is the 4th
         
    =  - cal_days_in_month(CAL_GREGORIANdate(n), date('Y'));

    }
    // There it is
    // All nice and organized. 
    // Will output "Thursday 10th of December 2009 is the next thursday"
    echo date('l jS of F Y'mktime(000date(n), , date(Y)))." is the next thursday";
    Enjoi :]

    --m4rx
    • [ 1 ] Thanks
  • Thanks Tyler, I made a sketch on a napkin and you turned it into some snazzy code.
    • [1] reply
    • strtotime FTW

      <?php
      echo date('l, F j, Y', strtotime('this Thursday'));
      ?>

      Will print today's date, if today is Thursday, although if today is Friday, it will print next Thursday's date, which may not be your intent. You may have intended to print yesterday's date, if today is Friday.
      • [ 2 ] Thanks
  • Oh, that's slick, MemberCon guys. (Is it both of you behind the user name here?) I occasionally tinker to patch up a php script, but I'm not a die-hard php developer and it never occured to me to look for a function like this. Hector might only need that one line.
  • Wow.. sorry guys.. I've been real busy and couldn't reply bck..

    YES YES YES YES.. thank you MemberCon.. that's exactly it.. i need for it to give me the next thursday..

    I kno I might've confused a few with my initial post but.. I found the script that did what I asked for and then realized that I needed it to tell me next week's thursday if it was friday or saturday....

    So thank you MemberCon.... and all the other warriors for helping out.. there are some really talented people on here

    -Hector
  • Very Very nice.
    Never acctually had to deal with time, so I have little idea on how to use the PHP functions.

    Love the one line, so much less complicated than mine :]

    --m4rx
  • Banned
    [DELETED]
  • The easy way:
    Code:
    echo 'Next Week: '. date('l, F j, Y', strtotime('+1 week'));

Next Topics on Trending Feed