thecreator thecreator - 1 month ago 7
MySQL Question

Get data from the current time

I have a table called

events
and I have two columns called
eventDate
and `timeĀ“

The point is, I insert the time manually and I would like to get the events today at the time that I have in my column
time


EX:

eventDate | time
26-10-2016 | 19:45


I would like to get at 19:45 the event and after two hours dissapear


I tried it but didn't work:


SELECT COUNT(*) FROM events WHERE eventDate = DATE_FORMAT(CURDATE(), '%d-%m-%Y') AND time >= NOW() - INTERVAL 2 HOUR


Forget the COUNT(*) I'm just using it to check

Answer

Something like this work?

SELECT COUNT(*) FROM events WHERE eventDate = DATE_FORMAT(CURDATE(), '%d-%m-%Y') AND time >= DATE_FORMAT(DATE_ADD(NOW(), INTERVAL -2 HOUR),'%H:%i');