3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $dateTime = new DateTime('2015-01-07 14:19:14', new DateTimeZone('UTC')); $dateTime->sub(new DateInterval('PT24H')); $begin = $dateTime; $end = new DateTime( '2015-01-07 14:19:14' ); $end = $end->modify( '-1 hour' ); $interval = new DateInterval('PT1H'); $daterange = new DatePeriod($begin, $interval ,$end); foreach($daterange as $date){ echo $date->format("Y-m-d H") . "<br>"; } var_dump($dateTime->format('Y-m-d H e'));
based on Wnn4K
Output for 5.3.0 - 7.2.0
2015-01-06 14<br>2015-01-06 15<br>2015-01-06 16<br>2015-01-06 17<br>2015-01-06 18<br>2015-01-06 19<br>2015-01-06 20<br>2015-01-06 21<br>2015-01-06 22<br>2015-01-06 23<br>2015-01-07 00<br>2015-01-07 01<br>2015-01-07 02<br>2015-01-07 03<br>2015-01-07 04<br>2015-01-07 05<br>2015-01-07 06<br>2015-01-07 07<br>2015-01-07 08<br>2015-01-07 09<br>2015-01-07 10<br>2015-01-07 11<br>string(17) "2015-01-06 14 UTC"
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::sub() in /in/dhDrO on line 4
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/dhDrO on line 3
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/dhDrO on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/dhDrO on line 3