Page 1 of 1

Delete record if older than 5 minutes?

Posted: Sun Apr 08, 2007 7:10 pm
by ERuiz
Can someone help me with deleting a record, when that record is older than 5 minutes?

Someone gave me this query:

$query = "DELETE FROM liveacars WHERE last_update < NOW() - INTERVAL 300 SECOND";

But when I execute it, it does not delete the records.

FYI, the last_update field is set as timestamp and the value inside it is written like this for example: 2007-04-08 19:20:00

Thanks for any help, as I am going nuts trying to get this to work.

ERuiz

Posted: Sun Apr 08, 2007 7:40 pm
by timvw
Basically, you want to see if it was changed before NOW() - 300 seconds... Using DATE_SUB should allow you to do that...

Posted: Sun Apr 08, 2007 7:59 pm
by ERuiz
Thanks for the reply, but the previous code is now working! I switched the last_update flag to timestamp and now it's working. I had it as varchar. Maybe that was it.