|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-10-08 11:39 UTC] contactme at antonydandrea dot com
-Summary: DateTime::create from format doesn't have trailing 0.
+Summary: DateTime::create_from_format treats d like j for day
which is inconsistent
[2016-10-08 11:39 UTC] contactme at antonydandrea dot com
[2017-02-12 17:56 UTC] derick@php.net
-Status: Open
+Status: Not a bug
[2017-02-12 17:56 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 05:00:01 2026 UTC |
Description: ------------ In the documentation, 'd' for dates is supposed to be a 2 digit character. So if it is less than 10, there is a 0 in front, e.g. 09. DateTime::createfromformat is supposed to "Parses a time string according to a specified format" return false on failure. I would expect 'd' to reject strings that did not have two characters for strings. Yet it seems to accept it as valid like 'j'. It looks like PHP tries to be clever and automatically treat is as 'j', but I think this behaviour is inconsistent. Test script: --------------- $dateObj = date_create_from_format('Y-m-d', '1930-12-3'); var_dump($dateObj->format('Y-m-d'); Expected result: ---------------- I expect that for the sake of consistency, PHP returns false and fails to create an object based on the format. Actual result: -------------- It returns the object and the var_dump has the string "1930-12-03".