#35699 [Asn]: date() can't handle leap years before 1970

From: Date: Tue, 20 Dec 2005 15:20:56 +0000
Subject: #35699 [Asn]: date() can't handle leap years before 1970
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-90732@lists.php.net to get a copy of this message
ID: 35699 Updated by: derick@php.net -Summary: strtotime can't handle leap years before 1970 Reported By: iquito at gmx dot net Status: Assigned Bug Type: Date/time related Operating System: Debian Sarge PHP Version: 5.1.1 Assigned To: derick New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2005-12-16 06:11:58] 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 ! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35699&edit=1

« previous php.bugs (#90732) next »