|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35699 date() can't handle leap years before 1970
Submitted: 2005-12-16 06:11 UTC Modified: 2005-12-20 17:01 UTC
From: iquito at gmx dot net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.1.1 OS: Debian Sarge
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: iquito at gmx dot net
New email:
PHP Version: OS:


 [2005-12-16 06:11 UTC] iquito at gmx dot net
strtotime() doesn't seem to handle leap years before 1970 correctly, all dates in a leap year are off by one day when converted by strtotime().

Reproduce code:
/* shows 1964-06-07 instead of 1964-06-06 */

echo date('Y-m-d', strtotime('1964-06-06'));

/* shows the correct date, 1963-06-06, thus confirming that it has something to do with leap years, non-leap-years aren't affected. */

echo date('Y-m-d', strtotime('1963-06-06'));

/* curiously, also dates in january and february of a leap year are affected by this bug */

echo date('Y-m-d', strtotime('1964-01-06')); // returns 1964-01-07

Expected result:
echo date('Y-m-d', strtotime('1964-06-06')); // should return 1964-06-06 !

Actual result:
echo date('Y-m-d', strtotime('1964-06-06')); // returns 1964-06-07 !


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-20 16:20 UTC]
strtotime is actually corrrect here, it's the date() function that is broken:

$utc_time1 = strtotime('1964-01-01 00:00:00 UTC');
$utc_time2 = strtotime('1963-12-31 00:00:00 UTC');
echo $utc_time1, ':', $utc_time2, " - ", $utc_time1 - $utc_time2, "\n";
echo date(DATE_ISO8601, $utc_time1), "\n";
echo date(DATE_ISO8601, $utc_time2), "\n";

-189388800:-189475200 - 86400

compare timestamp with date program:
derick@kossu:~$ date +%s --date "1964-01-01 00:00:00 UTC"
derick@kossu:~$ date +%s --date "1963-12-31 00:00:00 UTC"

 [2005-12-20 17:01 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Feb 24 15:01:30 2020 UTC