开发者

select all records created within the hour

startTimestamp < date_sub(curdate(), interval 1 hour)

Will the (sub)query above return all records created within the hour? If not will someone please show me a correct one? The complete query may look as follows:

select * from table where startTimestamp < date_sub(curdate(), interv开发者_如何学JAVAal 1 hour);


Rather than CURDATE(), use NOW() and use >= rather than < since you want timestamps to be greater than the timestamp from one hour ago. CURDATE() returns only the date portion, where NOW() returns both date and time.

startTimestamp >= date_sub(NOW(), interval 1 hour)

For example, in my timezone it is 12:28

SELECT NOW(), date_sub(NOW(), interval 1 hour);
2011-09-13 12:28:53  2011-09-13 11:28:53

All together, what you need is:

select * from table where startTimestamp >= date_sub(NOW(), interval 1 hour);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜