> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# add_months

> 在给定的日期上增加指定数量的月份。

在给定的日期（DATE、DATETIME）上增加一个整数月，返回结果日期。

`months` 可以是正数或负数。

返回的日期部分将与日期中指定的部分相同，除非返回的月比给定日期的日部分少，在这种情况下，日将是返回的月的最后一天。

如果给定的日期无效或者为 NULL，则返回 NULL。

## 语法

```SQL theme={null}
ADD_MONTHS(date, months);
```

## 参数说明

* `date`: 给定的日期，可以是DATE、DATETIME 类型。
* `months`: 要增加的整数月。

## 返回值说明

返回值的数据类型为 DATETIME。

## 示例

```Plain Text theme={null}
> select add_months('2022-01-01', 2);
+-----------------------------+
| add_months('2022-01-01', 2) |
+-----------------------------+
| 2022-03-01 00:00:00         |
+-----------------------------+

> select add_months('2022-01-01', -5);
+------------------------------+
| add_months('2022-01-01', -5) |
+------------------------------+
| 2021-08-01 00:00:00          |
+------------------------------+

> select add_months('2022-01-31', 2);
+-----------------------------+
| add_months('2022-01-31', 2) |
+-----------------------------+
| 2022-03-31 00:00:00         |
+-----------------------------+

> select add_months('2022-01-31 17:01:02', 2);
+--------------------------------------+
| add_months('2022-01-31 17:01:02', 2) |
+--------------------------------------+
| 2022-03-31 17:01:02                  |
+--------------------------------------+

> select add_months('2022-01-31 17:01:02', -2);
+---------------------------------------+
| add_months('2022-01-31 17:01:02', -2) |
+---------------------------------------+
| 2021-11-30 17:01:02                   |
+---------------------------------------+
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.