note 127370 added to class.datetime
| From: | covaleski dot rafael at live dot com | Date: | Sat, 30 Jul 2022 13:16:49 +0000 |
| Subject: | note 127370 added to class.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219083@lists.php.net to get a copy of this message | ||
PHP objects can be compared and you can use this with DateTime.
An anonymous person posted a note about the comparisons returning FALSE on the first unequal
property found (https://www.php.net/manual/en/language.oop5.object-comparison.php#98725), but it
does not seem to affect DateTime objects when comparing dates with different timezones - at least in
the PHP version I used (8.0.13).
<?php
// Same timezone.
$a = new DateTime("2022-07-30 12:30:00+0300");
$b = new DateTime("2022-07-30 12:30:00+0300");
$c = new DateTime("2022-07-15 12:30:00+0300");
var_dump($a == $b); // True.
var_dump($a > $b); // False.
var_dump($a < $b); // False.
var_dump($a > $c); // True.
// Different timezones.
$c = new DateTime("2022-07-12 12:30:00+0300");
$d = new DateTime("2022-07-12 12:30:00+0000");
$f = new DateTime("2022-07-12 09:30:00+0000");
var_dump($c < $d); // True.
var_dump($c == $d); // False.
var_dump($c > $d); // False.
var_dump($c == $f); // True.
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 185.101.176.229)
----
Manual Page -- https://php.net/manual/en/class.datetime.php
Edit -- https://main.php.net/note/edit/127370
Del: integrated -- https://main.php.net/note/delete/127370/integrated
Del: useless -- https://main.php.net/note/delete/127370/useless
Del: bad code -- https://main.php.net/note/delete/127370/bad+code
Del: spam -- https://main.php.net/note/delete/127370/spam
Del: non-english -- https://main.php.net/note/delete/127370/non-english
Del: in docs -- https://main.php.net/note/delete/127370/in+docs
Del: other reasons-- https://main.php.net/note/delete/127370
Reject -- https://main.php.net/note/reject/127370
Search -- https://main.php.net/manage/user-notes.php