I want to delete data from database via corn.
For example: i need to delete my all data except last 24 hour.
My time format is UNIX time Like
1531920800
This should do the trick:
$time = time();
$oneDay = 60 * 60 * 24;
$yesterday = $time - $oneDay;
$sql = 'DELETE FROM tablename WHERE columname < ' . $yesterday;
You may use UNIX_TIMESTAMP()
to access the current time since the UNIX epoch, then adjust it backwards by 24 hours. Something like this:
DELETE FROM yourTable
WHERE ts_column < UNIX_TIMESTAMP() - (24*60*60);