MySQL add month


 

MySQL add month

In this section we will learn how to add 1 month, 2 months and 12 months to a date with the help of DATE_ADD function in MySQL.

In this section we will learn how to add 1 month, 2 months and 12 months to a date with the help of DATE_ADD function in MySQL.

MySQL add month

In this section we will learn how to add 1 month, 2 month and 12 month to a date object in MySQL.

The MySQL DATE_ADD function is used to add certain time interval to the date object. The MySQL DATE_ADD function can be used to add any time values to the date object.

DATE_ADD() function is used to add time values (intervals) to a date value

The following table shows the expected form of the expr argument for each unit value.

unit Value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'

So, based on your requirement you can use following parameter with the DATE_ADD function to add required time interval to a date object.

MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH

 

Following example shows how to add 1 month to a date object:

SELECT DATE_ADD('2008-12-15', INTERVAL 1 MONTH)

Output:

2009-01-15

Following example show how to add 2 months:

SELECT DATE_ADD('2010-12-15', INTERVAL 2 MONTH)

Output:

2011-02-15

Following example shows how to add 12 months:

SELECT DATE_ADD('2010-12-15', INTERVAL 12 MONTH)

Output:

2011-12-15

In this section you learned how to add months with the help of DATE_ADD function of MySQL.

Ads