3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('Asia/Tehran'); $date1 = new \DateTime('2019-08-21 12:47:24'); $date2 = new \DateTime('2019-09-24 11:47:24'); //$date2 = new \DateTime('2019-08-21 12:47:24'); $diff = $date1->diff($date2); $date3 = new \DateTime('@' . $date1->format('U')); $date4 = new \DateTime('@' . ($date2->format('U')-3600)); //Sun 22 set, 0.00 a.m, when local clocks were set backward 1 hour $diff2 = $date3->diff($date4); if ($diff->h < 0) { echo $diff->format('%R%a Total number of days as a result of a DateTime::diff() or (unknown) otherwise %d days not already covered by the month Time = %H:%I:%S') . PHP_EOL; echo $diff2->format('%R%a Total number of days as a result of a DateTime::diff() or (unknown) otherwise %d days not already covered by the month Time = %H:%I:%S') . PHP_EOL; }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
+33 Total number of days as a result of a DateTime::diff() or (unknown) otherwise 3 days not already covered by the month Time = -1:00:00 +33 Total number of days as a result of a DateTime::diff() or (unknown) otherwise 2 days not already covered by the month Time = 23:00:00

preferences:
161.36 ms | 402 KiB | 156 Q