3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('America/New_York'); //DST starts Apr. 2nd 01:00 and moves to 03:00 $start = new \DateTime('2006-04-02T01:00:00'); $end = new \DateTime('2006-04-02T04:00:00'); while($end > $start) { $now = clone $end; $end->sub(new \DateInterval('PT1H')); echo $end->format('Y-m-d H:i T') . PHP_EOL; if ($now == $end) { break; //remove this will result in an endless loop } } echo '-----' . \PHP_EOL; //DST ends Oct. 29th 02:00 and moves to 01:00 $date = new DateTime('2006-10-29T00:30:00'); foreach(range(1,4) as $i) { $date->add(new DateInterval('PT30M')); echo $date->format('Y-m-d H:i T'). PHP_EOL; }
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
2006-04-02 03:00 EDT 2006-04-02 01:00 EST ----- 2006-10-29 01:00 EDT 2006-10-29 01:30 EDT 2006-10-29 01:00 EST 2006-10-29 01:30 EST
Output for 5.4.24 - 5.4.45, 5.5.8 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.27, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
2006-04-02 03:00 EDT 2006-04-02 03:00 EDT ----- 2006-10-29 01:00 EDT 2006-10-29 01:30 EDT 2006-10-29 01:00 EST 2006-10-29 01:30 EDT
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.23, 5.5.0 - 5.5.7
2006-04-02 03:00 EDT 2006-04-02 03:00 EDT ----- 2006-10-29 01:00 EDT 2006-10-29 01:30 EDT 2006-10-29 02:00 EST 2006-10-29 02:30 EST
Output for 5.2.2 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 18 Fatal error: Call to undefined method DateTime::sub() in /in/ZNfgq on line 11
Process exited with code 255.
Output for 5.2.0 - 5.2.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 18 ----- Fatal error: Call to undefined method DateTime::add() in /in/ZNfgq on line 24
Process exited with code 255.
Output for 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 18 Fatal error: Class 'DateTime' not found in /in/ZNfgq on line 6
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 11 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 18 Fatal error: Call to undefined function date_default_timezone_set() in /in/ZNfgq on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Parse error: syntax error, unexpected T_VARIABLE in /in/ZNfgq on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Parse error: parse error, unexpected T_VARIABLE in /in/ZNfgq on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ZNfgq on line 7 Parse error: parse error in /in/ZNfgq on line 10
Process exited with code 255.

preferences:
269.94 ms | 401 KiB | 424 Q