Doc #66104 [Ver->Csd]: strtotime reports "2011-02-31" and "2011-11-31" as valid dates

From: Date: Thu, 28 Jan 2021 16:26:15 +0000
Subject: Doc #66104 [Ver->Csd]: strtotime reports "2011-02-31" and "2011-11-31" as valid dates
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18461@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66104&edit=1 ID: 66104 Updated by: cmb@php.net Reported by: papaulsh at gmail dot com Summary: strtotime reports "2011-02-31" and "2011-11-31" as valid dates -Status: Verified +Status: Closed Type: Documentation Problem Package: Date/time related PHP Version: Irrelevant Assigned To: girgias Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmbecker69@gmx.de Revision: http://git.php.net/?p=doc/en.git;a=commit;h=f3bc618211dd65a97eb427aceb9473d3b4a0c3d0 Log: Fix #66104: strtotime reports "2011-02-31" and "2011-11-31" as valid dates Previous Comments: ------------------------------------------------------------------------ [2019-04-09 13:17:45] salathe@php.net Just FYI, we already have a detailed note and explanation on the Date Formats [1] page about this behaviour. [1] https://www.php.net/manual/en/datetime.formats.date.php ------------------------------------------------------------------------ [2019-04-09 10:22:02] girgias@php.net Assigning to myself to remind me to add a note explaining the behavior of strtotime ------------------------------------------------------------------------ [2018-02-14 05:45:55] requinix@php.net I am rather tired of explaining this every other month. How about a note (warning?) that says something along the lines of how strtotime does not validate the input but instead tries to interpret it as a date in the most reasonable way possible. Month overflow is the most common issue by far; 2011-02-31 is not a valid date but the "most reasonable" interpretation of it is 3 days after 2011-02-28 which would be 2011-03-03. And other GNU/OSS date parsers act similarly. The other common issue is passing a timestamp and expecting to get that same value back (should have been "@timestamp") but strtotime reads it as some compound format without delimiters, like HHMMSSYYYY. ------------------------------------------------------------------------ [2018-02-13 17:33:57] cmb@php.net This looks more like a documentation problem. Actually, strtotime() is very liberal in what it takes. 2011-02-31 is simply treated as 2011-03-03. Use checkdate() to check whether a given date is valid. ------------------------------------------------------------------------ [2015-09-30 14:54:12] boliveirasilva at gmail dot com The same problem occurs for the following dates. (year doesn't matter) '02/31/2014', '2016/02/31', '02/30/2015', '2014/02/30', '02/29/2015', '2015/02/29', '31-02-2015', '2015-02-31', '30-02-2015', '2015-02-30', '29-02-2015', '2015-02-29', '11/31/2014', '2016/11/31', '31-11-2015', '2015-11-31' ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=66104 -- Edit this bug report at https://bugs.php.net/bug.php?id=66104&edit=1

« previous php.doc.bugs (#18461) next »