3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tz = new DateTimeZone('America/Chicago'); // A timezone that has DST $five_hours_interval = new DateInterval('PT5H'); $date = new DateTime("2019-11-03 00:00:00", $tz); // goes backward at 2am echo $date->format('c') . "\n"; // Add five hours and subtract 5 hours. The $newDate should then equal the date. $five_hours_later = $date->add($five_hours_interval); $newDate = $five_hours_later->sub($five_hours_interval); echo $newDate->format('c');
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
2019-11-03T00:00:00-05:00 2019-11-03T00:00:00-05:00

preferences:
71.39 ms | 1479 KiB | 4 Q