user3372120
user3372120

Reputation: 144

Delete records where timestamp is older than 5 minutes

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

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?

Upvotes: 2

Views: 757

Answers (1)

Mahesh Madushanka
Mahesh Madushanka

Reputation: 2998

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)

Upvotes: 2

Related Questions