Search code examples
mysqldate-arithmetic

mysql time difference


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.


Solution

  •  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