ADD_MONTHS
Description
Returns a Date or Datetime adjusted by the specified number of months, either forward (positive) or backward (negative), relative to the provided Date or Datetime.
Syntax
ADD_MONTHS(date/datetime, num) -> Date/Datetime
Parameters
| Parameter | Data Type | Required | Description |
|---|---|---|---|
| date/datetime | Date/Datetime | Yes | The original Date or Datetime to adjust. |
| num | Integer | Yes | The number of months to add (use a negative value to subtract months). |
Examples
ADD_MONTHS(DATE(2017, 9, 30), 5)
-- Adds 5 months to 2017-09-30.
-- Returns 2018-02-28, the last day of February 2018.ADD_MONTHS(NOW(), -2)
-- Subtracts 2 months from now.Tips
If the reference date is the last day of its month, the result is the last day of the target month. Otherwise, the function retains the same day if it exists in the target month; if the day does not exist, it returns the last day of the target month.
The return type depends on the first parameter: if it's a Date, the result is a Date; if it's a Datetime, the result is a Datetime.