Reputation: 2785
I am trying to do a little spam filter with mysql. I want to check the last record a user has created in a table and compare it to the current time. The time created is stored as date_created
with mysql datetime
format.
I have tryed TIMEDIFF()
, but I can't get it to work for me, please help.
Upvotes: 4
Views: 6465
Reputation: 22749
To get the most recent record and time diff to 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
Upvotes: 1
Reputation: 47620
SELECT count(*) FROM database WHERE date_created> NOW() - INTERVAL 1 HOUR AND user_id=17
If this query returns non-zero value, then there are rows, created on last hour by this user
Upvotes: 3