Oliver Oliver - 1 month ago 6
MySQL Question

MYSQL Date Copy & Update + 14days

I have a small invoice system and I added a new due_date field. To start using it I need to copy the date of the invoice to the new due_date but need to add 14 days.

date und due_date field are Type date

I know how I can copy

UPDATE `invoice` SET `date` = `duedate`;


I think I know how to add days

UPDATE `invoice` SET `date` = DATE_ADD(`date` , INTERVAL 14 DAY);


BUT I don't know how to do this in one step :)

Any help appreciated!

Answer

You can have a column's value in the set clause relate to another column:

UPDATE `invoice` SET `duedate` = DATE_ADD(`date`, INTERVAL 14 DAY);
Comments