SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date() question re: calling next three thursdays

    I've got a form for a weekly meeting w/a submission deadline. If it's Sunday through Friday at noon (actually I cut it off before noon because I wanted to give them time to fill out the form), I want to be able to offer the user the dates for the following three Thursdays. After Friday at noon, they get the three Thursdays after the next Thursday... But the dates echoing out aren't quite working the way I thought they would. (Today's date is the 18th with a w of 1, yet in the first option it's telling me the 11th is next Thursday.)

    PHP Code:
    $time=date("G:i:s");
    echo 
    $time; echo "<br />";
    $dayofweek=date("w");
    echo 
    $dayofweek;echo "<br />";
    $thursday=4;
    echo 
    $difference; echo "<br />"
    and then

    HTML Code:
      Preferred Date: 
      <SELECT name="date">
      <option value="">Choose a Date</option>
      <?php
    if ($dayofweek<=$thursday)
    {
    $difference=$thursday-$dayofweek;
    $nextthursday=$difference+7;
    $thursdayafternext=$difference+14;
    $thursdayafterthat=$difference+21;
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$nextthursday,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$nextthursday,date("Y")));echo "</option>";
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafternext,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafternext,date("Y")));echo "</option>";
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafterthat,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafterthat,date("Y")));echo "</option>";
    }
    elseif ( ($dayofweek==6) || ( ($time>="11:58:30")&&($dayofweek==5) ) )
    {
    $difference=$thursday-$dayofweek;
    $nextthursday=$difference+14;
    $thursdayafternext=$difference+21;
    $thursdayafterthat=$difference+28;
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$nextthursday,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$nextthursday,date("Y")));echo "</option>";
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafternext,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafternext,date("Y")));echo "</option>";
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafterthat,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafterthat,date("Y")));echo "</option>";
    }
    elseif ( ($time<="11:58:29")&&($dayofweek==5) )
    {
    $difference=$thursday-$dayofweek;
    $nextthursday=$difference+7;
    $thursdayafternext=$difference+14;
    $thursdayafterthat=$difference+21;
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$nextthursday,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$nextthursday,date("Y")));echo "</option>";
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafternext,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafternext,date("Y")));echo "</option>";
    echo "<option value=\"";date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafterthat,date("Y")));echo "\">";echo date("F d", mktime(0,0,0,date("m"),date("w")+$thursdayafterthat,date("Y")));echo "</option>";
    }
    ?>
      </SELECT><br />
    Also I'm not sure if just adding ws will work when the month (or year) changes...if it'll show December 28 and January 4 as options...

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $num_thursdays 4;
    for (
    $i 0$i $num_thursdays$i++) {
      
    $next_thursday strtotime("next thursday") + ((7*24*60*60) * $i);
      echo 
    date("F d"$next_thursday) . "<br />";



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
  •