Declaration
MONTHS_ADD(date, months)
Description
This function adds a specified number of months months to the date date.
Supported data types
The months_add function in OceanBase AI Database supports multiple time-related data types as inputs and determines the return type based on the input type. The specific correspondence is as follows:
- Input
DATEto return aDATEtype. - Input
DATETIMEreturnsDATETIMEtype. - Input
TIMESTAMPreturnsDATETIMEtype. - Input
VARCHAR(a string that can be parsed as a date) returnsDATETIMEtype. - When
TIMEis input, the function returns aDATETIMEvalue. For aTIMEvalue, the function takes its year, month, and day parts as the current date and performs the calculation with the given number of months.
Behavior description
- In OceanBase AI Database, the
month_addfunction returnsNULLfor invalid inputs instead of throwing an error. - Supports the
TIMEdata type, where the year, month, and day are set to the current time. - Determines whether to allow calculations involving invalid dates based on the
ALLOW_INVALID_DATESsetting. - When a single
SELECTstatement parameter is a string, it is uniformly converted to theDATETIMEtype before output.
Examples
Add 1 month to 2026-01-31.
obclient> SELECT MONTHS_ADD('2026-01-31', 1);
The return result is as follows:
+-----------------------------+
| MONTHS_ADD('2026-01-31', 1) |
+-----------------------------+
| 2026-02-28 00:00:00 |
+-----------------------------+
1 row in set