php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53834 mktime returns wrong date if used zero prefix in day
Submitted: 2011-01-25 08:03 UTC Modified: 2011-01-25 10:28 UTC
From: jpachta at centrum dot cz Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.5 OS: WinXP
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: jpachta at centrum dot cz
New email:
PHP Version: OS:

 

 [2011-01-25 08:03 UTC] jpachta at centrum dot cz
Description:
------------
When used mktime() with parameters with zero prefix in days 2011-01-08 and  2011-01-09 the function returns timestamp for GMT: Thu, 30 Dec 2010 23:00:00 GMT

Example: note zeros in month and day parameters
mktime(0,0,0,01,08,2011)) returns wrong date GMT: Thu, 30 Dec 2010 23:00:00 GMT
mktime(0,0,0, 1,08,2011)) returns wrong date GMT: Thu, 30 Dec 2010 23:00:00 GMT
mktime(0,0,0, 1, 8,2011)) returns correct date
mktime(0,0,0,01, 8,2011)) returns correct date

Test script:
---------------
echo 'Current PHP version: ' . phpversion(); // Current PHP version: 5.3.5

date_default_timezone_set('Europe/Prague');

echo "------\r\n";

echo "2011-01-07 => ", date('Y-m-d', mktime(0,0,0,01,07,2011)), " ", mktime(0,0,0,01,07,2011), " OK\r\n";
echo "2011-01-08 => ", date('Y-m-d', mktime(0,0,0,01,08,2011)), " ", mktime(0,0,0,01,08,2011), " WR\r\n";
echo "2011-01-09 => ", date('Y-m-d', mktime(0,0,0,01,09,2011)), " ", mktime(0,0,0,01,09,2011), " WR\r\n";
echo "2011-01-10 => ", date('Y-m-d', mktime(0,0,0,01,10,2011)), " ", mktime(0,0,0,01,10,2011), " OK\r\n";

echo "------\r\n";

echo "2011-1-06 => ", date('Y-m-d', mktime(0,0,0,1,06,2011)), " ", mktime(0,0,0,1,06,2011), " OK\r\n";
echo "2011-1-07 => ", date('Y-m-d', mktime(0,0,0,1,07,2011)), " ", mktime(0,0,0,1,07,2011), " OK\r\n";
echo "2011-1-08 => ", date('Y-m-d', mktime(0,0,0,1,08,2011)), " ", mktime(0,0,0,1,08,2011), " WR\r\n";
echo "2011-1-09 => ", date('Y-m-d', mktime(0,0,0,1,09,2011)), " ", mktime(0,0,0,1,09,2011), " WR\r\n";
echo "2011-1-10 => ", date('Y-m-d', mktime(0,0,0,1,10,2011)), " ", mktime(0,0,0,1,10,2011), " OK\r\n";

echo "------\r\n";

echo "2011-1-6 => ", date('Y-m-d', mktime(0,0,0,1,6,2011)), " ", mktime(0,0,0,1,6,2011), " OK\r\n";
echo "2011-1-7 => ", date('Y-m-d', mktime(0,0,0,1,7,2011)), " ", mktime(0,0,0,1,7,2011), " OK\r\n";
echo "2011-1-8 => ", date('Y-m-d', mktime(0,0,0,1,8,2011)), " ", mktime(0,0,0,1,8,2011), " WR\r\n";
echo "2011-1-9 => ", date('Y-m-d', mktime(0,0,0,1,9,2011)), " ", mktime(0,0,0,1,9,2011), " WR\r\n";
echo "2011-1-10 => ", date('Y-m-d', mktime(0,0,0,1,10,2011))," ", mktime(0,0,0,1,10,2011), " OK\r\n";


echo "------\r\n";

echo "2011-01-6 => ", date('Y-m-d', mktime(0,0,0,01,6,2011)), " ", mktime(0,0,0,1,6,2011), " OK\r\n";
echo "2011-01-7 => ", date('Y-m-d', mktime(0,0,0,01,7,2011)), " ", mktime(0,0,0,1,7,2011), " OK\r\n";
echo "2011-01-8 => ", date('Y-m-d', mktime(0,0,0,01,8,2011)), " ", mktime(0,0,0,1,8,2011), " WR\r\n";
echo "2011-01-9 => ", date('Y-m-d', mktime(0,0,0,01,9,2011)), " ", mktime(0,0,0,1,9,2011), " WR\r\n";
echo "2011-01-10 => ", date('Y-m-d', mktime(0,0,0,01,10,2011)), " ", mktime(0,0,0,1,10,2011), " OK\r\n"; 


Expected result:
----------------
In the test script above you can compare initial date and returned date. In my case for days 08 and 09 it returned date of 2010-12-31 which is wrong.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-25 08:08 UTC] jpachta at centrum dot cz
Current PHP version: 5.3.5------
2011-01-07 => 2011-01-07 1294354800 OK
2011-01-08 => 2010-12-31 1293750000 WR
2011-01-09 => 2010-12-31 1293750000 WR
2011-01-10 => 2011-01-10 1294614000 OK
------
2011-1-06 => 2011-01-06 1294268400 OK
2011-1-07 => 2011-01-07 1294354800 OK
2011-1-08 => 2010-12-31 1293750000 WR
2011-1-09 => 2010-12-31 1293750000 WR
2011-1-10 => 2011-01-10 1294614000 OK
------
2011-1-6 => 2011-01-06 1294268400 OK
2011-1-7 => 2011-01-07 1294354800 OK
2011-1-8 => 2011-01-08 1294441200 OK // this was marked in the script as WR by mistake
2011-1-9 => 2011-01-09 1294527600 OK // this was marked in the script as WR by mistake
2011-1-10 => 2011-01-10 1294614000 OK
------
2011-01-6 => 2011-01-06 1294268400 OK
2011-01-7 => 2011-01-07 1294354800 OK
2011-01-8 => 2011-01-08 1294441200 OK // this was marked in the script as WR by mistake
2011-01-9 => 2011-01-09 1294527600 OK // this was marked in the script as WR by mistake
2011-01-10 => 2011-01-10 1294614000 OK

Process completed, Exit Code 0.
Execution time: 00:00.203
 [2011-01-25 10:28 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-01-25 10:28 UTC] derick@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

Numbers with 0 are octal numbers. See the first warning at http://uk2.php.net/integer
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 00:01:26 2025 UTC