Bug #62179 [Asn->Nab]: strtotime returns current date instead of false or correct timestamp

From: Date: Tue, 20 Jan 2015 21:19:41 +0000
Subject: Bug #62179 [Asn->Nab]: strtotime returns current date instead of false or correct timestamp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190087@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62179&edit=1 ID: 62179 Updated by: derick@php.net Reported by: aldekein at myevil dot info Summary: strtotime returns current date instead of false or correct timestamp -Status: Assigned +Status: Not a bug Type: Bug Package: Date/time related Operating System: linux / windows PHP Version: 5.3.13 Assigned To: derick Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2013-12-06 10:07:42] 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. ------------------------------------------------------------------------ [2013-12-05 17:13:20] mike@php.net Unfortunately, strtotime just an algoritm, not a telepathic artificial intelligence. ------------------------------------------------------------------------ [2012-05-29 10:18:18] 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 ------------------------------------------------------------------------ [2012-05-29 10:12:03] aldekein at myevil dot info It tries to parse value as time. And strtotime('11.05.07 00:00:00') === false ------------------------------------------------------------------------ [2012-05-29 09:57:04] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62179&edit=1

« previous php.bugs (#190087) next »