<?php function roundTime($timestamp, $interval, $direction){ $rounded_seconds = 0; switch ($direction) { case "u": //round up $rounded_seconds = ceil($timestamp / ($interval * 60)) * ($interval * 60); break; case "d": //round down $rounded_seconds = floor($timestamp / ($interval * 60)) * ($interval * 60); break; default: echo "default"; } return date('H:i', $rounded_seconds) . "\n"; } $testTimes = [ "2023-05-30 14:05", "2023-05-30 14:23", "2023-05-30 14:35", "2023-05-30 14:40", "2023-05-30 14:55" ]; foreach ($testTimes as $time) { echo "base time: ".$time.PHP_EOL; echo "round up to 15 mins: ".roundTime(strtotime($time), 15, "u"); echo "round up to 30 mins: ".roundTime(strtotime($time), 30, "u"); echo "round down to 15 mins: ".roundTime(strtotime($time), 15, "d"); echo "round down to 30 mins: ".roundTime(strtotime($time), 30, "d"); echo PHP_EOL; }
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`