Jump to content

Help with Date Dropdown Menus


leachus2002

Recommended Posts

Hi There,

 

I am currently creating a call logging system in PHP and I want to be able to create a 3 stage drop down menu - that displays the date, 2 weeks from today.

 

For example, in normal html it would read:

 

<select name="date_day">

--options 1-31<option>1</option>

</select>

<select name="date_month">

--options 1-12<option>1</option>

</select>

<select name="date_year">

--10 years(2010-2020)<option>1</option>

</select>

 

Is there any way of php automating this so that the date 2 weeks ahead is displayed automatically? - but still allowing the users to select another date from the dropdown?

 

Thanks

Matt

 

Link to comment
https://forums.phpfreaks.com/topic/193457-help-with-date-dropdown-menus/
Share on other sites

<?php
$twoweekstoday = strtotime("+ 2 weeks");
$year2w = strftime("%Y",$twoweekstoday);
$month2w = strftime("%m",$twoweekstoday);
$day2w = strftime("%d",$twoweekstoday);
?>
<select name="day">
   <option value="">Select Day</option>
<?php
for($d=1;$d<32;$d++)
{
     $sel = ($d == $day2w)?'selected="selected"':'';
     echo '<option value="'.$d.'" '.$sel.'>'.$d.'</option>';
}
?>
</select>

 

And similar for month and year

 

 

<select name="month">

  <option value="">Select Month</option>

<?php

$months = array('January','February','March','April','May','June','July','August','September','October','November','December');

for($m=1;$m<13;$m++)

{

    $sel = ($m == $month2w)?'selected="selected"':'';

    echo '<option value="'.$m.'" '.$sel.'>'.$months[$m-1].'</option>';

}

?>

</select>

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.