DateTime.Now.AddMonths(Months)

.AddMonths(Months) adds the specified number of months to the DateTime object. To subtract months, simply supply the Months parameter with a negative number.

Note: the AddMonths() method adds the months to the date or variable calling it. You cannot do something like this:

var ldToday = DateTime.Today;

var ldNextMonth = ldToday.AddMonths(1);

ldToday will be the same as ldNextMonth.

Applies To

Properties and Methods

None

Available

The .AddMonths(Months) method is available in:

  • 15.03.016
  • All newer builds

Type

DateTime

Syntax

DateTime.Now.AddMonths(Months);

Parameters

Parameter

Required

Description

Months

Yes

An integer value. Can be positive or negative.

Non-integers will generate a scripting error.

Example

var ldNew = new DateTime('6/10/2021 12:34:56');

var ldNewA = new DateTime('6/10/2021 12:34:56').AddMonths(1);

var ldNewB = new DateTime('6/10/2021 12:34:56').AddMonths(10);

var ldNewC = new DateTime('6/10/2021 12:34:56').AddMonths(100);

var ldNewD = new DateTime('6/10/2021 12:34:56').AddMonths(1000);

var ldNewE = new DateTime('6/10/2021 12:34:56').AddMonths(-10);

Event.Form.MessageBox('Add Months to ' + ldNew.ShortDateString + ':' +

'\n1 Month: ' + ldNewA.ShortDateString +

'\n10 Months: ' + ldNewB.ShortDateString +

'\n100 Months: ' + ldNewC.ShortDateString +

'\n1000 Months: ' + ldNewD.ShortDateString +

'\n-10 Months: ' + ldNewE.ShortDateString);

 

/* Expected Prompt response:

Add Months to 06/10/2021:

1 Month: 07/10/2021

10 Months: 04/10/2022

100 Months: 10/10/2029

1000 Months: 10/10/2104

-10 Months: 08/10/2020

*/