sql query - how to filter results from last hour? [closed]
I would only like to get only the data from the last hour. the query should be something like that...
SELECT some_date_related_data FROM some_table
WHERE time > now() - (1hour)
how can i achieve that?
Thanks!
Since you used NOW()
, I'm guessing this is about MySQL. Then I'd suggest reading the manual :-)
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
For MySQL:
WHERE time > NOW() - INTERVAL 1 HOUR ;
or
WHERE time > DATE_ADD( NOW(), INTERVAL -1 HOUR ) ;
For MS-Access:
WHERE time > DateAdd( 'h', -1, Now() ) ;
If it's MSSQL it'll be:
DateDiff(hh,time,GetDate()) < 1
Or mySQL, you'll find the altfernative here:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_datediff
NOW()
returns you a timestamp, so you can use it in following way:
SELECT some_date_related_data FROM some_table
WHERE time > ( now() - 3600 )
精彩评论