8

Is there a simple way of getting the current time and rounding it up to the next quarter of an hour?

For example if it is 12:36 then display 12:45 if it's 13:01 then display 13:15

etc

user3305539
  • 123
  • 1
  • 5
  • Should be able to do a variant of this: http://stackoverflow.com/questions/9303604/rounding-up-a-number-to-nearest-multiple-of-5 – JensB May 22 '14 at 11:40
  • 1
    first hit on google -> http://stackoverflow.com/questions/2480637/round-minute-down-to-nearest-quarter-hour – davidkonrad May 22 '14 at 11:40
  • Rounding down and rounding up are slightly different, so this question is unique. Links above go to a question for rounding down. – steampowered Dec 31 '14 at 20:36

1 Answers1

8

here is your answer

$current_date = date('d-M-Y g:i:s A');
echo $current_date."<br/>";
$current_time = strtotime($current_date);

$frac = 900;
$r = $current_time % $frac;

$new_time = $current_time + ($frac-$r);
$new_date = date('d-M-Y g:i:s A', $new_time);

echo $new_date."<br/>";

LIVE DEMO

Satish Sharma
  • 9,547
  • 6
  • 29
  • 51