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) == 2) ? (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; } } echo $diff; $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 - 7.1.0
92014-05-05 12:25:00 12:16
Output for 5.2.0 - 5.2.17
9 Fatal error: Call to undefined method DateTime::add() in /in/NW7Zq on line 25
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/NW7Zq 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/NW7Zq 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/NW7Zq on line 6