MySQL Delete Records Older Than X Minutes?
- by sajanNOPPIX
I've searched quite a bit and found a few solutions that didn't end up working for me and can't understand why.
I have a table with a timestamp column. The MySQL type for this column is 'datetime'. I insert into this table the following from PHP.
date('Y-m-d H:i:s')
This enters, what looks like the correct value for the MySQL date time.
2012-06-28 15:31:46
I want to use this column to delete rows that are older than say 10 minutes. I'm running the following query, but it's not working. It affects 0 rows.
DELETE FROM adminLoginLog WHERE timestamp < (NOW() - INTERVAL 10 MINUTE);
Can anyone shed some light as to what I'm doing wrong and why it's not working properly?
Thanks.
Update: It looks like my first issue is that I'm using DATETIME when I should be using the TIMESTAMP data type. I'm updating my code to do that now. Thanks.