MYSQL Time interval

0

I need to search a server, through a command, for a 2 hour interval of a saved data in relation to the server time.

Example : An employee opens a call; this call will be saved to the bank on date X with the 12:00:00 time and its status will be "OPEN". I need to fetch all calls that were not resolved within a 2 hour interval.

SELECT datas FROM banco WHERE DATE_SUB(CURDATE(), INTERVAL 2 HOUR) <= datas AND status='2';

The purpose of this command is to search the database for call times and compare with the system time. If it's been two hours, it will show, if not, it will not show.

When I give this command, it shows me this data,

The command was given at 15:03, only he showed other schedules, plus 2 hours open.

    
asked by anonymous 11.10.2018 / 20:04

1 answer

1

Your select returns this because CURDATE only returns the current date without the time. Use NOW() in the calculation, because it returns current date and time:

SELECT datas FROM banco WHERE datas >= DATE_SUB(NOW(),INTERVAL 2 HOUR) AND status='2';
    
11.10.2018 / 20:10