php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36748 gmdate returning March twice under 'F' through a loop.
Submitted: 2006-03-15 18:24 UTC Modified: 2006-03-15 21:50 UTC
From: admin at yawnster dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.1.2 OS: WinXP
Private report: No CVE-ID: None
 [2006-03-15 18:24 UTC] admin at yawnster dot com
Description:
------------
The gmdate() function produces March twice and misses out October under certain conditions.

Reproduce code:
---------------
<div id="month">
	<select name="month">
<?php 
	for($i = 1; $i <=12; $i++)
	{
		$date = gmdate('F', mktime(0, 0, 0, $i, 1, 2006));
		echo("<option value='$i'>$date</option>");
	}
?>
	</select>
</div>

Expected result:
----------------
Well it should produce a list of the Months in order into a drop-box.

Actual result:
--------------
Well it gives out the 12 months, but goes through March Twice, but misses out October.. This problem however doesnt occur within the date() function, so for the time being I'll use this..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-15 21:19 UTC] derick@php.net
Works fine, which timezone does the following print:

<?php
echo date("e"), "\n";
?>

 [2006-03-15 21:25 UTC] admin at yawnster dot com
http://82.44.194.226/test.php

Its says im in Europe/London which is indeed correct..

I also included the file code within the test.php file so you can see the problem firsthand..

Alex
 [2006-03-15 21:50 UTC] derick@php.net
No bug here, you're mixing a function that works on local time (mktime) with one that works on gmt times (gmdate). If you mix that you get time skews. See the following correct script:

<?php
date_default_timezone_set("Europe/London");
for($i = 1; $i <=12; $i++)
{
    $date1 = gmdate('F '.DATE_ISO8601, gmmktime(0, 0, 0, $i, 1, 2006));
    echo "with mktime:    $date1\n";
}
?>

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 13:01:30 2024 UTC