[SOLVED] Another Time Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

[SOLVED] Another Time Question

Post 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?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

your way seems pretty easy ;)
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Thanks guys, I guess I'll stick with what I've got :-)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

why not just

Code: Select all

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