Updated on 2026-11-06 GMT+08:00

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

Table 1 Parameter descriptions

Parameter

Mandatory

Type

Description

start_date

Yes

DATE or STRING

The start date.

Supports the following formats:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:mi:ss
  • yyyy-mm-dd hh:mi:ss.ff3

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.