简体   繁体   中英

How do i delete data from database except last 24 hour UNIX Time Format

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM