ADD_MONTHS
Description
The ADD_MONTHS
function is used to add a specified number of months numMonths
to a given date startDate
. The result will return a new date. If the resulting date exceeds the range of days in the target month, the function will automatically adjust the date to the last day of that month. If the calculated result exceeds the date range supported by the system, it will return NULL
.
Parameter Description
startDate
: Date type, representing the starting date for the month addition calculation.numMonths
: Integer type, representing the number of months to add. It can be a positive number (indicating a future date) or a negative number (indicating a past date).
Return Result
Returns a date type, representing the date after the month addition.
Example
- Example of adding months:
- Example of Reducing Months:
- Example of exceeding the number of days in a month:
- Example of exceeding the system date range:
Notes
- Ensure that the
startDate
parameter is in a valid date format, otherwise the function will returnNULL
. - When
numMonths
is a relatively large or small integer, please check whether the resulting date is within the date range supported by the system.