php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53431 strtotime/DateTime object return incorrect results for invalid date/times
Submitted: 2010-12-01 03:33 UTC Modified: 2010-12-01 04:58 UTC
From: adam-phpbugs at adam dot gs Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: ALL
Private report: No CVE-ID: None
 [2010-12-01 03:33 UTC] 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:
---------------
[adam@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

[adam@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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-01 03:36 UTC] adam-phpbugs at adam dot gs
I, obviously, swapped expected and actual here.
 [2010-12-01 04:58 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-12-01 04:58 UTC] aharvey@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 19:01:29 2024 UTC