aqDateTime.AddMonths Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

The aqDateTime.AddMonths method adds or subtracts the specified number of months to (from) the specified Date/Time value and returns the resultant date/time.

Declaration

aqDateTime.AddMonths(InputDate, Months)

InputDate [in]    Required    Date/Time    
Months [in]    Optional    Integer Default value: 1   
Result Date/Time

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

InputDate

Specifies the original date and time.

Months

Specifies the number of months to change. If Months is positive, then the given number is added. If Months is negative, then the given number is subtracted.

Result Value

The value of the Date/Time type that is earlier or later than InputDate by the number of months specified.

Remarks

If an invalid date is generated upon adding or subtracting a month, the last day of the resulting month is returned. For example:

January 31st + 1 month = February 31st (not a valid day) = February 29th (leap year) or February 28th (non-leap year)

May 31st - 1 month = April 31st (not a valid day) = April 30th

Example

The code below demonstrates how you can change a date and/or time by adding some values to it.

JavaScript, JScript

function ChangingTime()
{
  var Time1, Time2, Time3, Time4, Time5, Time6, Time7;

  Time1 = aqDateTime.Now();
  Time2 = aqDateTime.AddDays(Time1, 5);
  Time3 = aqDateTime.AddHours(Time1, 7);
  Time4 = aqDateTime.AddMinutes(Time1, 24);
  Time5 = aqDateTime.AddMonths(Time1, 2);
  Time6 = aqDateTime.AddSeconds(Time1, 15);
  Time7 = aqDateTime.AddTime(Time1, 9, 3, 24, 51);

  Log.Message(aqConvert.DateTimeToStr(Time1));
  Log.Message(aqConvert.DateTimeToStr(Time2));
  Log.Message(aqConvert.DateTimeToStr(Time3));
  Log.Message(aqConvert.DateTimeToStr(Time4));
  Log.Message(aqConvert.DateTimeToStr(Time5));
  Log.Message(aqConvert.DateTimeToStr(Time6));
  Log.Message(aqConvert.DateTimeToStr(Time7));
}

Python

def ChangingTime():
  Time1 = aqDateTime.Now()
  Time2 = aqDateTime.AddDays(Time1, 5)
  Time3 = aqDateTime.AddHours(Time1, 7)
  Time4 = aqDateTime.AddMinutes(Time1, 24)
  Time5 = aqDateTime.AddMonths(Time1, 2)
  Time6 = aqDateTime.AddSeconds(Time1, 15)
  Time7 = aqDateTime.AddTime(Time1, 9, 3, 24, 51)
  
  Log.Message(aqConvert.DateTimeToStr(Time1))
  Log.Message(aqConvert.DateTimeToStr(Time2))
  Log.Message(aqConvert.DateTimeToStr(Time3))
  Log.Message(aqConvert.DateTimeToStr(Time4))
  Log.Message(aqConvert.DateTimeToStr(Time5))
  Log.Message(aqConvert.DateTimeToStr(Time6))
  Log.Message(aqConvert.DateTimeToStr(Time7))

VBScript

Sub ChangingTime
  Dim Time1, Time2, Time3, Time4, Time5, Time6, Time7

  Time1 = aqDateTime.Now
  Time2 = aqDateTime.AddDays(Time1, 5)
  Time3 = aqDateTime.AddHours(Time1, 7)
  Time4 = aqDateTime.AddMinutes(Time1, 24)
  Time5 = aqDateTime.AddMonths(Time1, 2)
  Time6 = aqDateTime.AddSeconds(Time1, 15)
  Time7 = aqDateTime.AddTime(Time1, 9, 3, 24, 51)

  Log.Message aqConvert.DateTimeToStr(Time1)
  Log.Message aqConvert.DateTimeToStr(Time2)
  Log.Message aqConvert.DateTimeToStr(Time3)
  Log.Message aqConvert.DateTimeToStr(Time4)
  Log.Message aqConvert.DateTimeToStr(Time5)
  Log.Message aqConvert.DateTimeToStr(Time6)
  Log.Message aqConvert.DateTimeToStr(Time7)
End Sub

DelphiScript

procedure ChangingTime;
var Time1, Time2, Time3, Time4, Time5, Time6, Time7;
begin
  Time1: = aqDateTime.Now;
  Time2: = aqDateTime.AddDays(Time1, 5);
  Time3: = aqDateTime.AddHours(Time1, 7);
  Time4: = aqDateTime.AddMinutes(Time1, 24);
  Time5: = aqDateTime.AddMonths(Time1, 2);
  Time6: = aqDateTime.AddSeconds(Time1, 15);
  Time7: = aqDateTime.AddTime(Time1, 9, 3, 24, 51);

  Log.Message(aqConvert.DateTimeToStr(Time1));
  Log.Message(aqConvert.DateTimeToStr(Time2));
  Log.Message(aqConvert.DateTimeToStr(Time3));
  Log.Message(aqConvert.DateTimeToStr(Time4));
  Log.Message(aqConvert.DateTimeToStr(Time5));
  Log.Message(aqConvert.DateTimeToStr(Time6));
  Log.Message(aqConvert.DateTimeToStr(Time7));
end;

C++Script, C#Script

function ChangingTime()
{
  var Time1, Time2, Time3, Time4, Time5, Time6, Time7;

  Time1 = aqDateTime["Now"]();
  Time2 = aqDateTime["AddDays"](Time1, 5);
  Time3 = aqDateTime["AddHours"](Time1, 7);
  Time4 = aqDateTime["AddMinutes"](Time1, 24);
  Time5 = aqDateTime["AddMonths"](Time1, 2);
  Time6 = aqDateTime["AddSeconds"](Time1, 15);
  Time7 = aqDateTime["AddTime"](Time1, 9, 3, 24, 51);

  Log["Message"](aqConvert["DateTimeToStr"](Time1));
  Log["Message"](aqConvert["DateTimeToStr"](Time2));
  Log["Message"](aqConvert["DateTimeToStr"](Time3));
  Log["Message"](aqConvert["DateTimeToStr"](Time4));
  Log["Message"](aqConvert["DateTimeToStr"](Time5));
  Log["Message"](aqConvert["DateTimeToStr"](Time6));
  Log["Message"](aqConvert["DateTimeToStr"](Time7));
}

See Also

Working With Dates
Working With Time
AddTime Method
AddDays Method
AddHours Method
AddMinutes Method
AddSeconds Method
TimeInterval Method

Highlight search results