How can I list the MM/DD/YY for the next 4 Thursdays?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajcolburn
    New Member
    • Jan 2007
    • 11

    #1

    How can I list the MM/DD/YY for the next 4 Thursdays?

    Hi there,
    I'm fairly new to PHP and can't work out how to do this:
    I'd like to list the short date of the next 4 'thursdays' in a drop-down menu, e.g.

    The date today is 01/02/2007 so ideally the drop down would contain the following options:

    01/04/2007
    01/11/2007
    01/18/2007
    01/25/2007

    There must be a simple solution!
    Many thanks for any help or hints in advance,
    Alex.
  • aparna8
    New Member
    • Jan 2007
    • 4

    #2
    [PHP]
    //get Numeric representation of today's day
    $day = date('w');

    //Get the day difference
    if ($day <= 4) {
    $dayDiff = 4 - $day;
    } else {
    $dayDiff = (6 - $day + 1) + 4 ;
    }

    for ($i=0;$i<4;$i++ ) {

    $Thursdays[] = date('m-d-Y',mktime(0,0,0 ,date('m'),date ('d') + $dayDiff + (7 * $i),date('Y'))) ;
    }

    print_r($Thursd ays);
    [/PHP]

    Comment

    • ajcolburn
      New Member
      • Jan 2007
      • 11

      #3
      Aparna, thanks so much for that, I wasn't expecting such a quick and straight-forward response!

      Kind regards,
      Alex.

      Comment

      Working...