3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $start = new DateTime("Now"); $start->add(new DateInterval('PT1H')); $newTime = $start->getTimestamp() - round($start->getTimestamp() / (15 * 60)) * (15 * 60); $start->modify("-" . abs($newTime) . " seconds"); $end = new DateTime("2015-05-16 17:00"); $interval = new DateInterval('PT15M'); $period = new DatePeriod($start, $interval, $end); $current_date = date('d-M-Y g:i:s A'); $current_time = strtotime($current_date); foreach ($period as $dt) { echo $dt->format('H:i')."<br>"; }
Output for 5.6.28, 7.0.20 - 7.2.6
15:47<br>16:02<br>16:17<br>16:32<br>16:47<br>
Output for 5.3.0 - 5.6.23, 7.0.0 - 7.0.8
15:45<br>16:00<br>16:15<br>16:30<br>16:45<br>
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::add() in /in/oc2t5 on line 4
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/oc2t5 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/oc2t5 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/oc2t5 on line 3