Jump to content

select form - dates - tuesdays


nbarone

Recommended Posts

I am wondering how I would make a <select> box in php, that goes from June 30th 2009 (5/30/09) to (dynamic date) and shows only TUESDAYS.

 

it should be formatted like so:

<option value="2009/05/30">June 30th, 2009</option>

 

Thanks!

Link to comment
Share on other sites

<?php
  $start = strtotime('2009-05-27');
  $end = strtotime('2009-07-12');
  $dow = 2; //1 = Mon, 2 = Tues, 3 = Wed, etc
  $offset = $dow - date('N',$start);
  if($offset < 0) $offset += 7;
  print '<select name="date">';
  for($date = strtotime('+'.$offset.' days',$start);$date <= $end;$date = strtotime('+1 week',$date)){
    printf('<option value="%s">%s</option>',$date,date('F jS Y',$date));
  }
  print '</select>';
?>

Link to comment
Share on other sites


<?php

$startDate = array('06/30/2009', strtotime('June 30th 2009'));

$endDate = array('08/30/2009', strtotime('August 30th 2009'));

$inc = $startDate[1];

while ($inc < $endDate[1]) {

     $inc = $inc + 604800;

     $options[] = "<option value='" . date('Y/m/d', $inc) . "'>" . date('F jS, Y', $inc) . "</option>";

}

?>

<select name='date' id='date'>

<option value='<?=$startDate[0];?>'><?=date ('F jS, Y', $startDate[1]);?></option>

<?php 

foreach ($options as $value) {

     echo $value . "\n";
     
}

?>

<option value='<?=$endDate[0];?>'><?=date ('F jS, Y', $endDate[1]);?></option>

</select>

Link to comment
Share on other sites

<?php
define('SECONDS_PER_WEEK', 604800);
$startDate = mktime(0, 0, 0, 6, 30, 2009);
$endDate = $startDate + (SECONDS_PER_WEEK * 10); // 10 weeks past $startDate

for($date = $startDate; $date <= $endDate; $date += SECONDS_PER_WEEK) {
printf('<option value="%s">%s</option>', date('n/j/Y', $date), date('F jS, Y', $date));
}
?>

 

Doubt you needed this many answers, but I wrote it and dammit if I'm going to let it go to waste.

Link to comment
Share on other sites

<?php
  $start = strtotime('2009-05-27');
  $end = strtotime('2009-07-12');
  $dow = 2; //1 = Mon, 2 = Tues, 3 = Wed, etc
  $offset = $dow - date('N',$start);
  if($offset < 0) $offset += 7;
  print '<select name="date">';
  for($date = strtotime('+'.$offset.' days',$start);$date <= $end;$date = strtotime('+1 week',$date)){
    printf('<option value="%s">%s</option>',$date,date('F jS Y',$date));
  }
  print '</select>';
?>

 

oh yeah...this line:

    printf('<option value="%s">%s</option>',$date,date('F jS Y',$date));

should be:

    printf('<option value="%s">%s</option>',date('Y/m/d',$date),date('F jS Y',$date));

Link to comment
Share on other sites

I am wondering how I would make a <select> box in php, that goes from June 30th 2009 (5/30/09) to (dynamic date) and shows only TUESDAYS.

 

it should be formatted like so:

<option value="2009/05/30">June 30th, 2009</option>

 

Thanks!

Am I the only one on here that noticed that June is the 6th month and not the 5th??

 

"June 30th 2009 (5/30/09)"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.