rokr1
rokr1

Reputation: 23

Sql query for deleting rows before a certain year

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

Answers (2)

Bhavik Patel
Bhavik Patel

Reputation: 1074

You can try this query

DELETE FROM `tablename` where YEAR(`date`) < '2012'

Upvotes: 0

Vivek Sadh
Vivek Sadh

Reputation: 4268

You can do it this way:

DELETE FROM tablename WHERE date < '2012-01-01 00:00:00';

Upvotes: 5

Related Questions