Reputation: 11
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 minutes. It should show records of current date only
This is what I tried:
SELECT * FROM jqcalendar WHERE StartTime <= NOW() - INTERVAL 5 MINUTE
Upvotes: 1
Views: 4999
Reputation: 6448
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
Upvotes: 2
Reputation: 2238
have you tried
StartTime > NOW() - INTERVAL 5 MINUTE
? I think you just turned around your operator.
Upvotes: 1
Reputation: 12628
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
Upvotes: 2