add_months
The add_months function is used to calculate the date obtained by adding a specified number of months to a date value. That is, the date that is num_months months after start_date.
Syntax
add_months(string start_date, int num_months)
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| start_date | Yes | DATE or STRING | The start date. Supports the following formats:
|
| num_months | Yes | INT | The number of months to add. |
Return Values
Returns the date obtained by adding num_months months to the start_date. The return value format is yyyy-mm-dd.
Returns a date value of type DATE.
- If start_date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
- If start_date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
- If the start_date value is NULL, an error is returned.
- If the num_months value is NULL, NULL is returned.
Example Code
- Example 1
select add_months('2023-02-26',3);Returns 2023-05-26.
- Example 2
select add_months('2023-02-14 21:30:00',3);Returns 2023-05-14.
- Example 3
select add_months('2023-08-15 20:00:00',null);Returns NULL.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot