Aditya K
Aditya K

Reputation: 167

Alter year in a MySQL table

We have a column called date which is type datetime in a MySQL table, in which accidentally rows got added with the wrong year in.

E.g. 2015-09-30 23:57:29 instead of 2014-09-30 23:57:29

Is there a quick to change all these dates to the correct year? I was thinking of using date_sub but wasn't sure of the exact syntax?

Upvotes: 0

Views: 57

Answers (1)

Joe Taras
Joe Taras

Reputation: 15379

Try this:

UPDATE yourtable SET field = DATE_SUB(field, INTERVAL 1 YEAR)
WHERE YEAR(field) = 2015

I suppose you want to change all rows with year 2015. If your condition is different, please feel free to change it

Upvotes: 1

Related Questions