leachus2002 Posted February 26, 2010 Share Posted February 26, 2010 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 More sharing options...
jl5501 Posted February 26, 2010 Share Posted February 26, 2010 <?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 Link to comment https://forums.phpfreaks.com/topic/193457-help-with-date-dropdown-menus/#findComment-1018479 Share on other sites More sharing options...
leachus2002 Posted February 26, 2010 Author Share Posted February 26, 2010 Thanks for that - I have got the day working properley - but I cannot for the life of me figure out the month and year - can you point me in the right direction please? Thanks Matt Link to comment https://forums.phpfreaks.com/topic/193457-help-with-date-dropdown-menus/#findComment-1018551 Share on other sites More sharing options...
jl5501 Posted February 26, 2010 Share Posted February 26, 2010 <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> Link to comment https://forums.phpfreaks.com/topic/193457-help-with-date-dropdown-menus/#findComment-1018610 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.