NYCPHP Meetup

NYPHP.org

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

Tom Sartain tomsartain at gmail.com
Thu May 1 12:16:17 EDT 2008


If you're grouping results from MySQL, you should definitely look into using
the built in MySQL date/time functions first. The database will pretty much
always be better at grouping, filtering and organizing your data than code
would be.

The date function page is here:
http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html

But since you're not grouping by hours on the hour, but hours on the half
hour, I'd suggest writing a MySQL function to do that grouping for you, then
call that in your query. More info on functions:
http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

You might actually be able to search out some functions that others have
written that do similar things, since it doesn't seem like you're trying to
do something that nobody else has ever done.

-Tom


On Wed, Apr 30, 2008 at 12:33 PM, Allen Shaw <ashaw at polymerdb.org> wrote:

> John Campbell wrote:
>
> > round(seconds / 3600)
> > e.g.
> >
> > ROUND(TIME_TO_SEC('00:39:38')/3600) ;
> >
> Should have thought of converting to seconds... doh!  Thanks John and
> Brent.
> - A.
>
> --
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20080501/74fbc9a9/attachment.html>


More information about the talk mailing list