Delete database records WHERE timestamp=>'time() + 300'

Hi,

I am trying to delete all records in a database when they are over 5 minutes old.

[php]
$time = time();
$delete = time() + 300;

$delete_query(“DELETE from sessions WHERE timestamp=>’$delete’”) or die(mysql_error());[/php]

This code doesn’t work for me, it isn’t returning a mysql_error, just a server error page.

Any help appreciated!
Thanks,
James

That’s because you’re finding timestamps greater than the time the query is executed plus 5 minutes.

I’m pretty sure you want this:

DELETE FROM `sessions` WHERE UNIX_TIMESTAMP(`timestamp`)+300 < NOW()

Thanks :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service