ADD_MONTHS

Syntax

ADD_MONTHS
(
  date    IN,
  number  IN 
)
RETURNS date;

ADD_MONTHS
(
  TIMESTAMP WITH TIME ZONE  IN,
  number                    IN
)
RETURNS TIMESTAMP WITHOUT TIME ZONE;

Overview

The ADD_MONTHS function returns a new date or timestamp that is the given date or timestamp plus the number of months you specify.

Internally, it decomposes the input date into years, months, and days, and then adds the total number of months to calculate a new year and month.

In particular, if the input date is the last day of the current month, it will be adjusted to the last day of the new month.

If the first argument is timestamptz, it will keep the existing time information after calculating the date.

Parameters

Parameter
Description

date

date type: represents the date it is based on.

timestamp with timezone

timestamptz type: represents the date+ time+timezone.

number

integer, double precision, numeric type: represents the number of months to be added and is internally converted to an integer.

Example

# test 1
select oracle.add_months('2023-01-31'::date, 3);

 add_months 
------------
 2023-04-30
(1 row)

# test 2
select oracle.add_months('2023-01-31'::date, 3.9999);

 add_months 
------------
 2023-04-30
(1 row)

# test 3
SELECT oracle.ADD_MONTHS('2023-01-31 15:30:00+09'::timestamptz, 1);

     add_months      
---------------------
 2023-02-28 15:30:00
(1 row)

# test 4
SELECT oracle.ADD_MONTHS('2023-01-31 15:30:00+09'::timestamptz, 1.3);

     add_months      
---------------------
 2023-02-28 15:30:00
(1 row)

Last updated