AddMonthsToDate (open)

Adds a number of months to a date

Syntax

LOADLIB "wh::datetime.whlib";

DATETIME FUNCTION AddMonthsToDate(INTEGER months, DATETIME date, RECORD options)

Parameters

INTEGER months

The number of months to add to the timestamp. This value can also be negative.

DATETIME date

The timestamp to add the days to

RECORD options

Options

BOOLEAN roundforward

Round up/forward towards next year. Defaults to TRUE

Return value

DATETIME

A DateTime value representing @italic date to which @italic add_months has been added

Description

This function returns the specified timestamp, with the specified number of months added. If adding the specified number of months would return an invalid date, the date is rounded as specified to a valid date

Examples

// Add 5 months to the current date
DATETIME newdate := AddMonthsToDate(5, GetCurrentDateTime());

// Add 1 month to the current date, date is rounded forward
// Returns 2010-03-01
DATETIME newdate := AddMonthsToDate(1, MakeDate(2010, 1, 31));