Search code examples
mysqlintervals

Delete 24 Hours older records in PHP using Mysql


Queries are working fine. I just want to know the role of the INTERVAL keyword in these queries


Delete 30 minutes older records using Mysql

DELETE FROM `token_tbl` WHERE `dateCreate` < (Now() - INTERVAL 30 MINUTE);

Delete 1 Hour older records using Mysql

DELETE FROM `token_tbl` WHERE `dateCreate` < (Now() - INTERVAL 1 HOUR);

Delete 24 Hours older records using Mysql

DELETE FROM `token_tbl` WHERE `dateCreate` < (Now() - INTERVAL 24 HOUR);

Solution

  • interval denotes a period of time. I.e., Now() - INTERVAL 1 MINUTE means "one minute before the current time". Then the condition would be any records that have dateCreate that are older than a minute ago.