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.
date_created
datetime
I tried TIMEDIFF() but I can't get it to work for me, please help.
TIMEDIFF()
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
To get the latest information about the recording time and time for the current time for user x
x
SELECT tab.*, TIMEDIFF(NOW(), date_created) as diff FROM tab WHERE(userid = x) ORDER BY date_created DESC LIMIT 1