DateTime.addMonth()

Signature

DateTime addMonth (DateTime date, int months)

Domain

action, condition

Description

Adds a number of months to a DateTime and returns the result. The input DateTime is not modified.

Parameters

NameTypeDescription
dateDateTimeA DateTime to add some amount of time to.
monthsintThe number of months to add to the DateTime.

Returns

TypeDescription
DateTimeA new DateTime that results from adding the number of time units to the date argument.

Cautions

none

Example


Date dateNow = Date.now ();
String start = DateTime.format (dateNow, "yyyy-MM-dd HH:mm:ss");
String result = DateTime.format (DateTime.addMonth(dateNow, 1), "yyyy-MM-dd HH:mm:ss");

Result is:
start contains: "2004-03-11 14:59:04"
result contains: "2004-04-11 14:59:04"