Jump to content

Round time to nearest quarter


V

Recommended Posts

I'm having trouble rounding time

 

For example I have 01:08:34 and I want to round it to the nearest quarter (and eliminate seconds). I should get 01:00:00 or 01:41:00 to 01:45:00

 

I'm  using the following code but it doesn't work

 

$time = strtotime("01:08:34");
$round = 15;
$rounded = (round($time * 60 / $round) * $round) / 60;
echo gmdate("H:i:00", $rounded);

 

The output is 01:08:00, the same time not rounded. Please advise me how to do this right.

 

 

Link to comment
https://forums.phpfreaks.com/topic/263556-round-time-to-nearest-quarter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.