Edit report at http://bugs.php.net/bug.php?id=51866&edit=1
ID: 51866 Updated by: der...@php.net Reported by: smalyshev at sugarcrm dot com Summary: DateTime::createFromFormat does not match documentation Status: Assigned Type: Bug Package: Date/time related Operating System: * PHP Version: 5.3SVN-2010-05-20 (SVN) -Assigned To: derick +Assigned To: salathe New Comment: The docs are wrong here. If you specify a format letter, that information needs to be there. Previous Comments: ------------------------------------------------------------------------ [2010-05-21 00:05:22] s...@php.net I don't think it's a docs problem - it'd be much better if DateTime actually did what the docs say - at least as one of the options. Without it, if you have a string with date in it, you can not really find out where the date begins and ends and have no way to do parsing of partial dates. ------------------------------------------------------------------------ [2010-05-20 10:20:06] sala...@php.net I believe this is an issue of documentation rather than implementation, the quoted portion of the manual describes different behaviour than what the code appears to do. I'll assign this to Derick to confirm one way or the other. ------------------------------------------------------------------------ [2010-05-20 04:02:19] s...@php.net It also would be nice if this function could ignore extra input after the parsing and/or return where it stopped. ------------------------------------------------------------------------ [2010-05-20 04:01:27] smalyshev at sugarcrm dot com Description: ------------ The manual for DateTime::createFromFormat says: Format accepted by date(). If format does not contain the character ! then portions of the date/time value specified in format but not specified in time will be set to the current system time. However if you specify format like "d-m-Y H:i" and provide datetime string that does not contain time, parsing would fail - even though the manual says if time string does not contain parts from format it should use current system. Test script: --------------- <?php $date = DateTime::createFromFormat("d-m-Y H:i", "25-10-2007"); var_dump($date); Expected result: ---------------- Something like: object(DateTime)#1 (3) { ["date"]=> string(19) "2007-10-25 18:58:31" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "America/Los_Angeles" } Actual result: -------------- bool(false) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51866&edit=1