Reputation: 23
How can I delete all the rows before a certain year(say 2012) in MySQL, where the date column is in DATETIME format? ex:
DELETE FROM table_name WHERE date<2012;
Is not working.
Upvotes: 1
Views: 6415
Reputation: 1074
You can try this query
DELETE FROM `tablename` where YEAR(`date`) < '2012'
Upvotes: 0
Reputation: 4268
You can do it this way:
DELETE FROM tablename WHERE date < '2012-01-01 00:00:00';
Upvotes: 5