Results 1 to 2 of 2

Thread: Need some quick PHP date/time help.

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default Need some quick PHP date/time help.

    Hi all,

    I have little experience with PHP, so I found the following function which returns the two-digit day of the Nth occurrence of a day of the week in a given month/year:

    PHP Code:
        function date_from_nameday($occurrence$name_of_day$month$year)
        {
        
    $one_day 24 60 *60;
        
    $one_week $one_day;
        
        
    $one mktime(000$month1$year);
        
    $two $one $one_day;
        
    $three $two $one_day;
        
    $four $three $one_day;
        
    $five $four $one_day;
        
    $six $five $one_day;
        
    $seven $six $one_day;
        
        
    $first date('N'$one);
        
    $second date('N'$two);
        
    $third date('N'$three);
        
    $fourth date('N'$four);
        
    $fifth date('N'$five);
        
    $sixth date('N'$six);
        
    $seventh date('N'$seven);
        
        switch(
    $name_of_day)
        {
        case 
    $first$first_occurrence $one; break;
        case 
    $second$first_occurrence $two; break;
        case 
    $third$first_occurrence $three; break;
        case 
    $fourth$first_occurrence $four; break;
        case 
    $fifth$first_occurrence $five; break;
        case 
    $sixth$first_occurrence $six; break;
        case 
    $seventh$first_occurrence $seven; break;
        }
        
        
    $date_of_occurrence = ($occurrence 1) ? $first_occurrence + ($one_week * ($occurrence 1)) : $first_occurrence;
        
        
    $day_to_return date('d'$date_of_occurrence);
        
    $month_of_day date('m'$date_of_occurrence);
        if (
    $month_of_day != $month)
        return -
    1;
        else
        return 
    $day_to_return;
        } 
    And I have used it to find the first Tuesday of each month like this:

    PHP Code:
        if(time() > mktime(000date('m'), date_from_nameday(12date('n'), date('Y')), date('y'))){
            echo 
    '<span id="hfb_TickerMonth">'.date('F'mktime(000date('n')+1date('j'), date('y'))).'</span>';
            echo 
    '<span id="hfb_TickerDay">'.date_from_nameday(12date('n')+1date('Y')).'</span>';
        } else {
            echo 
    '<span id="hfb_TickerMonth">'.date('F').'</span>';
            echo 
    '<span id="hfb_TickerDay">'.date_from_nameday(12date('n'), date('Y')).'</span>';
        } 
    The if statement is checking whether or not today is beyond the first Tuesday, in which case I look for the following month's first Tuesday.

    Problem is, now I need it to take the time of day into account as well, and only look for the following month's first Tuesday if today is both beyond the first Tuesday and past 7:00 PM.

    How do I go about this? Do I just change the hour parameter from 0 to 19? That was my best guess, and that's what I did, but don't know if it did the trick or not.

    Thanks!
    My site: FreshCut :)

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Have tried php date function? http://www.php.net/manual/en/function.date.php

    and why cant u tell if it worked?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •