Finding time in mysql

0

Colleagues,

I have a system from which you are storing users' registration times in the following format in the Mysql database:

  

11:11:00 (the time can be any other according to the user's registration)

However, I created a Cron task where, every minute, it checks the database and performs a task based on the user's schedule. I used the following code for verification:

SELECT * FROM tabela WHERE DATE_FORMAT(Data, '%Y-%m-%d') = CURDATE() AND Hora =  TIME(CURRENT_TIMESTAMP);

The problem is that if the code hour above passes the registration time, it does not execute the task.Ex.:

Registration time is 11:11 am and the code time is 11:11:01, does not perform the task.

    
asked by anonymous 22.05.2017 / 21:57

1 answer

1

Try to use TIME_FORMAT

SELECT * FROM tabela WHERE DATE_FORMAT(Data, '%Y-%m-%d') = CURDATE() AND TIME_FORMAT(Hora,'%h:%i') =  TIME_FORMAT(TIME(CURRENT_TIMESTAMP),'%h:%i');

link

    
22.05.2017 / 22:33