Page 1 of 1

[SOLVED] Another Time Question

Posted: Fri Nov 07, 2003 7:03 pm
by mrvanjohnson
I have another time question.

I am grabbing the current time when someone hits the page. I want to the round that time up to the next quarter of an hour. So if you hit the page at 4:25 then it is rounded to 4:30 .. 4:31 rounds to 4:45 and so on.

I checked the round and ceil function but they don't look like they would work.

I guess I could always use logic to break it down... Something like

Code: Select all

<?php
$minutes = date ("i");
$minutes=($minutes >= 1 && $minutes <= 14)? 15:$minutes;
$minutes=($minutes >= 16 && $minutes <= 29)? 30:$minutes;
$minutes=($minutes >= 31 && $minutes <= 44)? 45:$minutes;
$minutes=($minutes >= 46 && $minutes <= 59)? 00:$minutes;
echo $minutes;
?>
But I was hoping there was an easier way. Does anyone have any ideas?

Posted: Fri Nov 07, 2003 7:04 pm
by d3ad1ysp0rk
your way seems pretty easy ;)

Posted: Fri Nov 07, 2003 7:07 pm
by Gen-ik
I think your bit of code looks like the thing you will need to use. As far as I know there are no build-it functions which do what you're after.

Posted: Fri Nov 07, 2003 7:57 pm
by mrvanjohnson
Thanks guys, I guess I'll stick with what I've got :-)

Posted: Sat Nov 08, 2003 12:14 pm
by Weirdan
why not just

Code: Select all

echo (15*(int)(date("i")/15))."\n";
?