|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-06 06:48 UTC] 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 22:00:01 2025 UTC |
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" }