Home > database >  how to increment a date column by one month in mysql?
how to increment a date column by one month in mysql?

Time:01-11

for the table

id start end
1 2021-01-01 2021-01-31
2 2021-02-01 2021-02-28
3 2021-01-01 2021-03-31

I want all the columns to be incremented by 1 month

id start end
1 2021-02-01 2021-02-28
2 2021-03-01 2021-03-31
3 2021-02-01 2021-04-30

is there a function for this?

CodePudding user response:

You may add one day to your end dates, then take the last day of the resulting date:

SELECT id,
       start   INTERVAL 1 MONTH AS start,
       LAST_DAY(end   INTERVAL 1 DAY) AS `end`
FROM yourTable
ORDER BY id;

screen capture from demo link below

Demo

CodePudding user response:

If you are looking to update your table for permanently. You can use the below query

To update start column

update yourTable set start=date_add(start,interval 1 MONTH);

and to update end column

update yourTable set end=date_add(end,interval 1 MONTH);
  •  Tags:  
  • Related