Jump to content

select form - dates - tuesdays


nbarone

Recommended Posts

<?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>';
?>


<?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>

<?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.

<?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));

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)"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.