#49480 [Opn]: DateTime::createFromFormat uses current system time to fill missing fields

From: Date: Sun, 06 Sep 2009 10:44:06 +0000
Subject: #49480 [Opn]: DateTime::createFromFormat uses current system time to fill missing fields
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2735@lists.php.net to get a copy of this message
ID: 49480 Updated by: derick@php.net Reported By: grodny at oneclick dot sk Status: Open -Bug Type: Date/time related +Bug Type: Documentation problem PHP Version: 5.3.0 New Comment: This is correct behaviour, you can change it by using a format like: <?php var_dump( DateTime::createFromFormat('!Y-m-d', '2009-03-02') ); ?> object(DateTime)#1 (3) { ["date"]=> string(19) "2009-03-02 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/London" } Previous Comments: ------------------------------------------------------------------------ [2009-09-06 06:48:54] grodny at oneclick dot sk Description: ------------ DateTime::createFromFormat uses current system time to fill missing fields instead of zero values, which leads to inconsistent comparsions and intervals returned by DateTime::diff. DateTime::createFromFormat('Y-m-d', '2009-03-02') should always create object(DateTime)#1 (3) { ["date"]=> string(19) "2009-03-02 00:00:00" ... } Reproduce code: --------------- <?php $A = DateTime::createFromFormat('Y-m-d', '2009-03-02'); sleep(2); $B = DateTime::createFromFormat('Y-m-d', '2009-03-02'); var_dump($A == $B); ?> Expected result: ---------------- bool(true) Actual result: -------------- bool(false) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49480&edit=1

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