note 102072 rejected from datetime.createfromformat by danbrown

From: Date: Wed, 26 Jan 2011 14:08:48 +0000
Subject: note 102072 rejected from datetime.createfromformat by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176331@lists.php.net to get a copy of this message
Note Submitter: stephen at sekka dot co dot uk ---- Be aware the following does NOT return false, <?php $date = DateTime::createFromFormat("Y-m-d", "10-01-01"); ?> It instead returns a DateTime object with a date of "0010-01-01 09:14:39". I'm still conflicted as to whether this is a bug in the code, or whether it's a bug in the documentation. The docs for the "Y" format character clearly state, "A full numeric representation of a year, 4 digits" If I were to use format('Y-m-d') on a DateTime object with a year of 10, it would give me "0010-01-01", as expected. However it seems createFromFormat() ignores the 4 digits part of the rule, and behaves like "Y" is instead "A full numeric representation of a year", which for 10 would indeed be 10. Personally, I would expect the above code to return false as 10 is not a full 4 digit year.

« previous php.notes (#176331) next »