3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // vychozi pripocet je cela ctvrthodina $diff = 15; $dt = new DateTime; $minutes = $dt->format('i'); $minutes = (strlen($minutes) == 1) ? (int) $minutes[1] : (int) $minutes; // najdi nejblizsi celou ctvrthodinu $quarters = array(15, 30, 45, 60); foreach($quarters as $quarter){ $curDiff = $quarter - $minutes; // pokud je interval mensi nez minuly a zaroven kladny // presne 0 je na dane ctvrthodine a to chceme pripocist plnych 15 min if($curDiff < $diff && $curDiff > 0){ $diff = $curDiff; } } $dt->add(new DateInterval('PT'.$diff.'M')); echo $dt->format('Y-m-d H:i:00').PHP_EOL; echo date('H:i');
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
2014-05-05 12:30:00 12:21
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::add() in /in/3BRBb on line 23
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/3BRBb on line 6
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/3BRBb on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/3BRBb on line 6