Friday, 15 July 2011

php - MySQL select from past clock hour -



php - MySQL select from past clock hour -

how select lastly clock hour. illustration if it's 3:30, how select 3 o'clock hour? know how lastly hr when query run, don't know how this.

for optimum performance, want predicate on bare column, rather wrapping column references in functions (as in selected answer).

to restrict rows returned have mydatetimecol values in current clock hour:

mydatetimecol >= date_format(now(),'%y-%m-%d %h:00:00')

the look on right side current datetime value rounded downwards hour. (in example, done formatting current datetime zeros minutes , seconds portion. not way this, method easier read of others.)

note there no need wrap column reference in function. using bare column reference mydatetimecol in predicate enables mysql utilize index range scan on mydatetimecol.

php mysql sql database

No comments:

Post a Comment