php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21966 date() or mktime() returning bad value for mktime month param of '2'
Submitted: 2003-01-30 12:40 UTC Modified: 2003-01-31 18:40 UTC
From: david at sxsw dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 4.2.2 OS: Gentoo Linux 1.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david at sxsw dot com
New email:
PHP Version: OS:

 

 [2003-01-30 12:40 UTC] david at sxsw dot com
#!/usr/bin/php -q
<?
system("cat test");
for($x=1; $x<=12; $x++) {
    echo "$x = ".date("m", mktime(0,0,0,$x))."\n";
}
?>
1 = 01
2 = 03
3 = 03
4 = 04
5 = 05
6 = 06
7 = 07
8 = 08
9 = 09
10 = 10
11 = 11
12 = 12

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-30 13:26 UTC] michael dot mauch at gmx dot de
See what you get if you use the "r" format:

# php -r 'for($x=1; $x<=3; $x++) {
    echo "$x = ".date("r", mktime(0,0,0,$x))."\n"; }'
1 = Thu, 30 Jan 2003 00:00:00 +0100
2 = Sun,  2 Mar 2003 00:00:00 +0100
3 = Sun, 30 Mar 2003 00:00:00 +0100

So apparently the "February, 30th" is turned into its normal representation by mktime(). Although that doesn't seem to be documented, I think that's a feature, because it helps doing date calculations.
 [2003-01-31 18:40 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Reason explained in previous comment.
 [2004-04-04 07:32 UTC] john dot j at fphoenix dot co dot uk
This bug does exist in 4.3.4 running on Mac OS X 
10.2.8.  It is directly related to the daylight saving 
time changeover date (28 March 2004 in the UK).  I 
recreate it using:

     <?php 
    {
	echo '<p>27/3/04 = ' . 
strval(mktime(00,0,0,3,27,2004)) . '</p>';   // 
1080345600
	echo '<p>28/3/04 = ' . 
strval(mktime(0,0,0,3,28,2004)) . '</p>';   // -3662  - 
should be 108042840
	echo '<p>28/3/04 = ' . 
strval(mktime(2,0,0,3,28,2004)) . '</p>';   // 
1080435600
	echo '<p>29/3/04 = ' . 
strval(mktime(0,0,0,3,29,2004)) . '</p>';   // 
1080514800 
	echo '<p>30/3/04 = ' . 
strval(mktime(0,0,0,3,30,2004)) . '</p>';   // 
1080601200
    } ?>

On the changeover date, times between midnight and 2 am 
exhibit the bug.  Times from 2 am onwards are correct.

I haven't checked, but I would bet the date in the 
original bug report was the DST changeover date for the 
locale of the person who submitted it.
 [2004-06-03 11:05 UTC] neilus at dcs dot kcl dot ac dot uk
this is re-occurring in the 4.3 tests, so either the test or bug needs to be fixed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 14:01:28 2024 UTC