DISPLAYING A LIST OF MONTHS WITH STRTOTIME - CAVEAT - Nov 19th, 2012


When a user had issues with displaying months in a pull down menu in a form using:


<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?> <?php selectedIf($month,@$_REQUEST['month']);?>"><?php echo
date("F",strtotime("0000-$month"));?></option>
<?php endforeach ?>
</select>

Greg Thomas, a programmer at Interactive Tools had this observation:

"In certain versions of PHP you can't leave any parts of a date string as 0 when using the strtotime function. Try
changing the code to look something like this:


<select name="month">
<?php foreach(range(1,12) as $month): ?>
<option value="<?php echo $month;?> <?php selectedIf($month,@$_REQUEST['month']);?>"><?php echo
date("F",strtotime("1985-$month-01 00:00:00"));?></option>
<?php endforeach ?>
</select>"




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service