|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-12-16 06:11 UTC] iquito at gmx dot net
Description:
------------
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 !
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 22:00:02 2025 UTC |
strtotime is actually corrrect here, it's the date() function that is broken: <?php date_default_timezone_set("UTC"); $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 1964-01-02T00:00:00+0000 1963-12-31T00:00:00+0000 compare timestamp with date program: derick@kossu:~$ date +%s --date "1964-01-01 00:00:00 UTC" -189388800 derick@kossu:~$ date +%s --date "1963-12-31 00:00:00 UTC" -189475200