NYCPHP Meetup

NYPHP.org

[nycphp-talk] rounding time values to the nearest hour

Brent Baisley brenttech at gmail.com
Tue Apr 29 14:26:30 EDT 2008


First, you need to convert it to a number, like minutes or seconds.
Then to round any number to any arbitrary interval, you can use this
formula:

round(num/interval)*interval

In your case the interval would be 60, but you would need to multiply
the end result by 60 (minutes) or 3600 (seconds) again to convert it
back to hours.

Brent Baisley
Systems Architect

On Tue, Apr 29, 2008 at 1:58 PM, Allen Shaw <ashaw at polymerdb.org> wrote:
> Hi Gang,
>
>  Anyone have a handy way to round time values to the nearest hour?
>  I've got time values stored in the database (MySQL) and often need to group
> them by the hour (e.g., times between 09:30 and 10:29 get grouped under
> 10:00).  Up to now I've been splitting on the colon and figuring it out
> based on the separate hour and minute values, but I thought there might be a
> better way...
>
>  Thanks,
>  Allen
>
>  --
>  Allen Shaw
>  slidePresenter (http://slides.sourceforge.net)
>
>  _______________________________________________
>  New York PHP Community Talk Mailing List
>  http://lists.nyphp.org/mailman/listinfo/talk
>
>  NYPHPCon 2006 Presentations Online
>  http://www.nyphpcon.com
>
>  Show Your Participation in New York PHP
>  http://www.nyphp.org/show_participation.php
>



More information about the talk mailing list