ADD_MONTHS macro

The ADD_MONTHS macro is available in HCL® Campaign

Syntax

ADD_MONTHS(months, date_string [, input_format])

Parameters

months

An integer that represents a number of months to add to the date_string.

date_string

A text string representing a valid date, in the format DELIM_M_D_Y, or in the format specified by the optional input_format argument.

input_format

The format that will be used for the calculated date. For a list of supported date formats, see the DATE_FORMAT function. Note that the input_format determines both the format of the input string and also the format of the output string.

Description

ADD_MONTHS returns a date after adding the specified number of months to the specified date_string. The date will be returned in the default format (DELIM_M_D_Y) or the format specified by the optional input_format argument. If you want a different format as the output, use DATE_FORMAT.

If increasing the month by the specified number of months produces an invalid date, then the result is calculated to be the last day of the month, as shown in the last example below. When necessary, leap years are taken into account. For example, adding one month to 31-Jan-2012 will result in 29-Feb-2012.

Examples

ADD_MONTHS(12, '06-25-11') adds one year (12 months) to the specified date and returns the date 06-25-12.

ADD_MONTHS(3, '2011-06-25', DT_DELIM_Y_M_D) adds three months to the specified date and returns the date 2011-09-25.

ADD_MONTHS(1, '02-28-2011') returns the date 03-28-2011.

ADD_MONTHS(1, '03-31-2012') returns the date 04-30-2012.

Related functions

Function Description
DATE Converts a date string into a Julian date.
DATE_FORMAT Transforms a date of input_format to output_format.