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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.