dev
dev

Reputation: 21

Procedure to delete all rows in a column older than 30 days

Can anyone please help me to write a procedure/function to delete the rows older than 30days from a column named prs_date from all tables in my database in mysql?

Upvotes: 0

Views: 828

Answers (2)

RafH
RafH

Reputation: 4544

this query can help

DELETE FROM sometable WHERE TO_DAYS(NOW()) - TO_DAYS(prs_date) <= 30;

Upvotes: 0

Marcus
Marcus

Reputation: 12596

Have a look at the DATEDIFF operator and combine it with CURDATE()

DELETE FROM myTable WHERE DATEDIFF(CURDATE(), prs_date) > 30;

Upvotes: 1

Related Questions