Mysql time difference

I am trying to make a small spam filter with mysql. I want to check the last record created by the user in the table and compare it with the current time. The created time is saved as date_created using the mysql datetime format.

I tried TIMEDIFF() but I can't get it to work for me, please help.

+4
source share
2 answers
  SELECT count(*) FROM database WHERE date_created> NOW() - INTERVAL 1 HOUR AND user_id=17 

If this query returns a nonzero value, then there are rows created in the last hour by this user

+3
source

To get the latest information about the recording time and time for the current time for user x

 SELECT tab.*, TIMEDIFF(NOW(), date_created) as diff FROM tab WHERE(userid = x) ORDER BY date_created DESC LIMIT 1 
+1
source

All Articles