3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('Europe/Minsk'); $a = new DateTimeImmutable("2015-01-01 10:00:00"); $daySchedule = [ 'from' => '11:00+03:00', 'till' => '21:00+03:00', ]; $from = explode(':', substr($daySchedule['from'], 0, 5)); $till = explode(':', substr($daySchedule['till'], 0, 5)); $fromTz = new \DateTimeZone(substr($daySchedule['from'], 5)); $tillTz = new \DateTimeZone(substr($daySchedule['till'], 5)); $b = $a->setTime($from[0], $from[1]); $b = $b->setTimezone($fromTz); var_dump($a > $b, $a, $b); var_dump($a->getTimestamp()); var_dump($b->getTimestamp()); var_dump($a > $b, $a, $b);
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" } int(1420095600) int(1420099200) bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" } int(1420095600) int(1420099200) bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" }

preferences:
122.3 ms | 403 KiB | 181 Q