add a year to existing date and update all records

I am trying to figure out how to take all the current dates in the field called dateCreated in the table clientRecords then add a year to dateCreated and update the field dateExpired in mySQL
Who is Participating?
nemws1Connect With a Mentor Database AdministratorCommented:
Not sure why gnoon is adding *three* years.  But yes, back up your data, as always, although I usually use 'mysqldump' instead of creating another table:
mysqldump dbname clientRecords > clientRecords.sql

Open in new window

And then use UPDATE and DATE_ADD to add one year:
UPDATE clientRecords
SET dateExpired=DATE_ADD(dateCreated, INTERVAL 1 YEAR)

Open in new window

-- firstly, backup the table
insert into clientRecords_bck select * from clientRecords;

-- then update value of dateExpired field, +3 years for example
update clientRecords set dateExpired=dateCreated+interval 3 year
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.