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

From: Date: Tue, 08 Sep 2009 09:09:38 +0000
Subject: #49480 [Csd->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-2738@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: Closed +Status: Open Bug Type: Documentation problem PHP Version: 5.3.0 New Comment: Let's keep it open though, so that it can be documented. Previous Comments: ------------------------------------------------------------------------ [2009-09-08 07:34:00] grodny at oneclick dot sk Such inconsistency and non-determinism in simple DateTime instance creation without using format modifier(undocumented one) can't be called correct. It's just how it was done :) Thanks anyway for hint. ------------------------------------------------------------------------ [2009-09-06 10:44:05] derick@php.net 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" } ------------------------------------------------------------------------ [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 (#2738) next »