blog code

Changing only the year in a mysql date or datetime field

Ever had to change only the year of an date-field? Continue reading to learn how!

For a datetime-field:

UPDATE table_name
SET date_column=DATE_FORMAT(date_column,'2016-%m-%d %T');

For a date-field:

UPDATE table_name
SET date_column=DATE_FORMAT(date_column,'2016-%m-%d');

Leave a Reply

Your email address will not be published. Required fields are marked *