Date: 08/31/99
- Next message: Richard Lynch: "Re: [PHP3] Date Stuff"
- Previous message: Andy Lewis: "[PHP3] Date Stuff"
- In reply to: Andy Lewis: "[PHP3] Date Stuff"
- Next in thread: Andy Lewis: "Re: [PHP3] Date Stuff"
- Reply: Andy Lewis: "Re: [PHP3] Date Stuff"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> Is there something wrong with this snippit?
>
> for ($i = 1; $i <= 13; $i++) {
> echo "<option VALUE=$i>";
> echo date("M", mktime(0,0,0,$i));
> echo "</option>\n";
> }
>
> I'm using it in a select statement and here's the output:
>
> <option VALUE=1>Jan</option>
> <option VALUE=2>Mar</option>
> <option VALUE=3>Mar</option>
> <option VALUE=4>May</option>
> <option VALUE=5>May</option>
> <option VALUE=6>Jul</option>
> <option VALUE=7>Jul</option>
> <option VALUE=8>Aug</option>
> <option VALUE=9>Oct</option>
> <option VALUE=10>Oct</option>
> <option VALUE=11>Dec</option>
> <option VALUE=12>Dec</option>
> <option VALUE=13>Jan</option>
>
> Any idea why the months are off?
Try it tomorrow, it will work perfectly! ;)
The problem is that when you do not supply arguments to mktime() the
current time's values will be filled in. Since you only supplied the
hour, minute, second and month arguments, the day and year are taken to be
today's date and year. And since today is the 31st you have a problem
because not all months have 31 days. mktime() tries to be smart about
this and figure that if you are asking for November 31, for example, that
you are actually talking about Dec.1.
The simple fix is to add a date to your mktime() call.
As in: mktime(0,0,0,$i,1)
-Rasmus
-- PHP 3 Mailing List <http://www.php.net/> To unsubscribe, send an empty message to php3-unsubscribe <email protected> To subscribe to the digest, e-mail: php3-digest-subscribe <email protected> To search the mailing list archive, go to: http://www.php.net/mailsearch.php3 To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Richard Lynch: "Re: [PHP3] Date Stuff"
- Previous message: Andy Lewis: "[PHP3] Date Stuff"
- In reply to: Andy Lewis: "[PHP3] Date Stuff"
- Next in thread: Andy Lewis: "Re: [PHP3] Date Stuff"
- Reply: Andy Lewis: "Re: [PHP3] Date Stuff"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

