开发者

Mysql Date and Time Difference

I have a table which has one field start_time with follwing records:

2011-07-26 14:30:00
    2011-07-28 08:00:00

What I need to do is compare the field start_time with the current date-time and show records only if the difference between them is less than 5 mi开发者_如何转开发nutes. It should show records of current date only

This is what I tried:

SELECT * FROM jqcalendar WHERE StartTime <= NOW() - INTERVAL 5 MINUTE


Use DATE_ADD/DATE_SUB for date-calculations:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

so StartTime <= DATE_SUB(NOW(), INTERVAL 5 MINUTE) should do the trick


use mysql function TIMEDIFF(date1, date2)

select * from jqcalendar WHERE  TIMEDIFF(now(), StartDate) < 500

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timediff


have you tried

StartTime > NOW() - INTERVAL 5 MINUTE

? I think you just turned around your operator.


TIMESTAMPDIFF(MINUTE,start_time,now()) < 5

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜