khristian Posted February 29, 2008 Share Posted February 29, 2008 Hi, I am trying to create a form which has a drop down box for the date, however I am having a few problems. What I want it to do is have a couple of standard options, and then todays date, and something like the next 28 days. I have tried <?$actiondate = date('j F Y');?> <form> <select name="date" size="1"> <option selected>-- SELECT --</option> <option>To Be Confirmed</option> <option><?echo $actiondate?></option> <option><?echo $actiondate+1?></option> <option><?echo $actiondate+2?></option> <option><?echo $actiondate+3?></option> <option><?echo $actiondate+4?></option> <option><?echo $actiondate+5?></option> </select> but all I get is: -- SELECT -- To Be Confirmed 29 February 2008 30 31 32 33 etc etc Any advice anyone? Quote Link to comment Share on other sites More sharing options...
KrisNz Posted March 1, 2008 Share Posted March 1, 2008 your $actiondate variable is a string, you can't just increment it that way. You need to use timestamps thusly... <select name="date"> <option value="">--Select Something--</option> <option value="TBC">T.B.C</option> <?php $now = time(); for ($i=0;$i<28;$i++) : $ts = $now + (86400 * $i); $date = date('j F Y',$ts); ?> <option value="<?php echo $ts ?>"><?php echo $date ?></option> <?php endfor; ?> </select> Also note that your option's need value attributes to be of any use In my example I've made that value the raw timestamp so you can easily convert it into whatever format you need when its sent back to the server for processing. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 1, 2008 Share Posted March 1, 2008 ...or this way using ISO date format for option values <?php $today = mktime(0,0,0); echo "<select name='date'>"; echo "<option selected>-- SELECT --</option><option>To Be Confirmed</option>"; for ($i=0; $i<29; $i++) { $t = strtotime("+$i days", $today); $val = date ('Y-m-d', $t); $opt = date ('d M Y', $t); echo "<option value='$val'>$opt</option>"; } echo '</select>'; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.