
# add_months
add_months函数用于计算日期值增加指定月数后的日期。即start_date在num_months个月之后的date。
#### 命令格式
```
add_months(string start_date, int num_months)
```
#### 参数说明
表1参数说明 
| 参数         | 是否必选 | 参数类型        | 说明                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|:---|:---|:---|:---|
| start_date | 是    | DATE或STRING | 代表起始日期。 支持以下格式： - yyyy-mm-dd  - yyyy-mm-dd hh:mi:ss  - yyyy-mm-dd hh:mi:ss.ff3   |
| num_months | 是    | INT         | 代表需要增加月的数量。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
   
#### 返回值说明
返回开始日期startdate增加num_months个月后的日期，返回值格式为yyyy-mm-dd。
返回值date类型的日期值。
![](https://support.huaweicloud.com/sqlref-spark-dli/public_sys-resources/note_3.0-zh-cn.png)
- startdate非DATE或STRING类型时，返回报错，错误信息：data type mismatch。
- startdate为DATE或STRING类型，但不符合日期值的入参格式时，返回NULL。
- startdate值为NULL时，返回报错。
- num_months值为NULL时，返回NULL。
 
#### 示例代码
返回2023-05-26。
```
select add_months('2023-02-26',3);
```
返回2023-05-14。
```
select add_months('2023-02-14 21:30:00',3);
```
返回NULL。
```
select add_months('20230815',3);
```
返回NULL。
```
select add_months('2023-08-15 20:00:00',null);
```
