php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62179 strtotime returns current date instead of false or correct timestamp
Submitted: 2012-05-29 09:57 UTC Modified: 2015-01-20 21:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: aldekein at myevil dot info Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.3.13 OS: linux / windows
Private report: No CVE-ID: None
 [2012-05-29 09:57 UTC] aldekein at myevil dot info
Description:
------------
So why do strtotime return current date instead of correct date or FALSE?

Test script:
---------------
$datetime = strtotime('11.05.07');
if ($datetime === false) die('fail');
echo date('d.m.Y', $datetime);

Expected result:
----------------
11.05.2007

Actual result:
--------------
29.05.2012 (current date)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-29 10:12 UTC] aldekein at myevil dot info
It tries to parse value as time.

And strtotime('11.05.07 00:00:00') === false
 [2012-05-29 10:18 UTC] aldekein at myevil dot info
I believe that there's a problem in format parser that cause disambiguation:

strtotime('24.11.07') is parsed as valid time.
strtotime('25.11.07') is parsed as valid date.

http://us2.php.net/manual/en/datetime.formats.date.php declares dd [.\t] mm "." yy
http://us2.php.net/manual/en/datetime.formats.time.php declares 't'? HH [.:] MM [.:] II
 [2013-12-05 17:13 UTC] mike@php.net
-Assigned To: +Assigned To: derick
 [2013-12-05 17:13 UTC] mike@php.net
Unfortunately, strtotime just an algoritm, not a telepathic artificial intelligence.
 [2013-12-06 10:07 UTC] aldekein at myevil dot info
Unfortunately so, but its result should be predictable. 
Returning current date on a bad string is the bad way, returning false (as it's written in the documentation) is a good way.
 [2014-01-15 00:28 UTC] neufeind@php.net
-Package: *General Issues +Package: Date/time related
 [2015-01-20 21:19 UTC] derick@php.net
-Status: Assigned +Status: Not a bug
 [2015-01-20 21:19 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The algorithm tries its best to be predictable. This is sadly one of the places where it can not. I'm closing this, as changing any of the parsing rules will break other things. And in the end, correct strings are correctly parsed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC