MySQL: How to delete records by date

Delete records where date is less than a certain date:
DELETE FROM `tablename` WHERE `date` < '2012-08-01';

You can also include intervals:
DELETE FROM `tablename` WHERE `date`  < DATE_SUB(NOW(), INTERVAL 3 MONTH);
DELETE FROM `tablename` WHERE `date`  < DATE_SUB(NOW(), INTERVAL 3 WEEK);
DELETE FROM `tablename` WHERE `date`  < DATE_SUB(NOW(), INTERVAL 2 DAY);

Comments

Popular posts from this blog

How to resolve 'res://ieframe.dll/acr_error.htm#' error (Internet Explorer stopped working while viewing a website)

htaccess: Redirecting multiple domains to the main domain

Removing index.php in Codeigniter using XAMPP on Windows