user3372120 user3372120 - 3 months ago 9x
MySQL Question

Delete records where timestamp is older than 5 minutes

I have a table called filesUploaded, with a column called dataTimer of type


When I record a new value in my table, I use the following command to enter the current date in timestamp format:

strtotime(date("Y-m-d H:i:s"));//Example: 145879957

To delete records that have more than 5 minutes in my table I use this syntax:

DELETE FROM filesUploaded WHERE dataTimer < (NOW() - INTERVAL 5 MINUTE)

But it is not working, what might be happening?


the issue is your storing it in the format of varchar .

you need to convert it to date format and the you can delete

DELETE FROM filesUploaded WHERE STR_TO_DATE(dataTimer,%Y-%m-%d %H:%M:%S) < (NOW() - INTERVAL 5 MINUTE)