Edit report at http://bugs.php.net/bug.php?id=53431&edit=1
ID: 53431 Updated by: ahar...@php.net Reported by: adam-phpbugs at adam dot gs Summary: strtotime/DateTime object return incorrect results for invalid date/times -Status: Open +Status: Bogus Type: Bug Package: Date/time related Operating System: ALL PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Like mktime() and pretty much every other date handling functions in PHP, strtotime() attempts to handle out of range input as best it can. In this case, the zeroth month of the year is December the previous year (ie the month before the first month of the year -- January) and the zeroth day of that month is the last day of the previous month. All of this works out to the last day of November the year before 2011, which obviously equates to November 30, 2010, which I presume was the current date when you lodged this bug report in your time zone. Not a bug -> closing. Previous Comments: ------------------------------------------------------------------------ [2010-12-01 03:36:45] adam-phpbugs at adam dot gs I, obviously, swapped expected and actual here. ------------------------------------------------------------------------ [2010-12-01 03:33:49] adam-phpbugs at adam dot gs Description: ------------ When given an invalid date/time both strtotime and the DateTime object returns the current day at midnight instead Test script: --------------- [a...@nighe]$ php -r '$x=strtotime("2011-00-00");printf("%s\n",date("Y-m-d H:i:s",$x));' 2010-11-30 00:00:00 [a...@nighe]$ php -r '$x=new DateTime("2011-00-00");var_dump($x);' object(DateTime)#1 (3) { ["date"]=> string(19) "2010-11-30 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "America/New_York" } Expected result: ---------------- returns current day at midnight Actual result: -------------- strtotime should return FALSE DateTime should throw an Exception. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53431&edit=1