aqDateTime.AddHours Method

Applies to TestComplete 14.92, last modified on September 16, 2021

Description

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

Declaration

aqDateTime.AddHours(InputDate, Hours)

InputDate [in]    Required    Date/Time    
Hours [in]    Required    Integer    
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.

Hours

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

Result Value

The value of the DateTime type that is earlier or later than InputDate by the number of hours specified.

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
AddMonths Method
AddDays Method
AddMinutes Method
AddSeconds Method
TimeInterval Method

Highlight search results