Page 1 of 1

Date has lost its way....

Posted: Thu Aug 01, 2013 9:05 pm
by orbdrums
I have the following code that worked great until today, August 1st, 2013. When I display the $v_month variable, it equals 08 but it selects January. If I hard code 08 in to the $v_month variable, it selects September. Any help would be appreciated.

Code: Select all

$v_month = substr(date("m/d/y"),0,2);

<select name="v_month" type="text" id="v_month">
<option value="01Jan"<? if($v_month==01){ echo 'selected'; } ?>>Jan</option>
<option value="02Feb"<? if($v_month==02){ echo 'selected'; } ?>>Feb</option>
<option value="03Mar"<? if($v_month==03){ echo 'selected'; } ?>>Mar</option>
<option value="04Apr"<? if($v_month==04){ echo 'selected'; } ?>>Apr</option>
<option value="05May"<? if($v_month==05){ echo 'selected'; } ?>>May</option>
<option value="06Jun"<? if($v_month==06){ echo 'selected'; } ?>>Jun</option>
<option value="07Jul"<? if($v_month==07){ echo 'selected'; } ?>>Jul</option>
<option value="08Aug"<? if($v_month==08){ echo 'selected'; } ?>>Aug</option>
<option value="09Sep"<? if($v_month==09){ echo 'selected'; } ?>>Sep</option>
<option value="10Oct"<? if($v_month==10){ echo 'selected'; } ?>>Oct</option>
<option value="11Nov"<? if($v_month==11){ echo 'selected'; } ?>>Nov</option>
<option value="12Dec"<? if($v_month==12){ echo 'selected'; } ?>>Dec</option>
</select>

Re: Date has lost its way....

Posted: Thu Aug 01, 2013 9:21 pm
by requinix
Leading zeros on numbers mean octal, and 08 and 09 are invalid octal numbers. Remove the zeros.

And the way you get $v_month is more complicated than it needs to be. Guess you don't know how date works?

Code: Select all

$v_month = date("n");

Re: Date has lost its way....

Posted: Thu Aug 01, 2013 9:30 pm
by orbdrums
Well I don't know a lot but thanks for your help and the link. It worked great!!

Re: Date has lost its way....

Posted: Fri Aug 02, 2013 2:22 pm
by Christopher

Code: Select all

<select name="v_month" type="text" id="v_month">
There is no type="text" attribute for the <select> tag. It is probably ignored, but show be removed.