Deleting rows older than 30 days in MySQL

If you want to delete rows older than xx dates using MySQL, here is a simple way of doing so:

DELETE FROM mytable WHERE date < DATE_SUB(NOW(), INTERVAL 30 DAY);

You could also use INTERVAL 1 MONTH.


4 Comments

RobbieJune 2nd, 2008 at 8:59 pm

Hey Thanks! This helped me clear out 135,000 records in about a minute.

somedoodMay 9th, 2009 at 11:04 am

Thanks, this made my night.

TomAugust 6th, 2011 at 7:05 pm

Robbie, you work for Pentagon? xD Btw: nice one with MySQL command :)

EricFebruary 8th, 2012 at 2:40 am

beautiful work – scheduled this with my wordpress install.

Leave a comment

Your comment