|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2016-01-29 14:33 UTC] derick@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: derick
[2016-01-29 14:33 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 22:00:02 2025 UTC |
Description: ------------ Two datetimes with all values the same (except microseconds) always compare as "equal". To put it another way, if you're trying to find out which one came first, you can't. Test script: --------------- $dt1 = new DateTime("2014-09-19 17:16:35.694274 America/Los_Angeles"); $dt2 = new DateTime("2014-09-19 17:16:35.728291 America/Los_Angeles"); var_dump($dt1 < $dt2); # bool(false) var_dump($dt1 == $dt2); # bool(true) # Not setting timezone because already have same timezone. var_dump($dt1->format("Y-m-d H:i:s.u") < $dt2->format("Y-m-d H:i:s.u")); # bool(true) var_dump($dt1->format("Y-m-d H:i:s.u") == $dt2->format("Y-m-d H:i:s.u")); # bool(false) Expected result: ---------------- The smaller datetime should compare as less than the larger one. To put this another way, the comparison of the objects should be the same whether you're comparing them as objects or as strings (and the string version is clearly correct IMO.)