Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
ERuiz
Forum Newbie
Posts: 2 Joined: Sun Apr 08, 2007 7:06 pm
Post
by ERuiz » Sun Apr 08, 2007 7:10 pm
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
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Sun Apr 08, 2007 7:40 pm
Basically, you want to see if it was changed before NOW() - 300 seconds... Using
DATE_SUB should allow you to do that...
ERuiz
Forum Newbie
Posts: 2 Joined: Sun Apr 08, 2007 7:06 pm
Post
by ERuiz » Sun Apr 08, 2007 7:59 pm
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.