aqDateTime.TimeInterval Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the aqDateTime.TimeInterval method to determine how much time has passed from one time value to another.

Declaration

aqDateTime.TimeInterval(InputTime1, InputTime2)

InputTime1 [in]    Required    Date/Time    
InputTime2 [in]    Required    Date/Time    
Result Date/Time

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

InputTime1

Specifies one of Date/Time values the interval between which should be calculated.

InputTime2

Specifies one of date/time values the interval between which should be calculated.

Result Value

A date/time value that denotes the period between the given date/time values. The returned value is absolute, it does not matter which of the date/time values is earlier.

Remarks

The returned time period is measured starting from the "zero date", which is 12:00 AM, December 30, 1899. However, if the period is less than one day, then the date portion is omitted. Besides, if your locale uses the 12-hour clock notation, the resulting value is displayed using "before noon" and "after noon" abbreviations (like AM/PM in English).

Because of these reasons, using the common aqConvert.DateTimeToStr method to display the TimeInterval results could yield quite odd results (like 12/31/1899 12:00:05 AM when the difference is 1 day and 5 seconds). This could be rather confusing for the values that reflect time duration. To avoid misunderstanding, it is better to use the dedicated method, TimeIntervalToStr, that returns a string in the D:HH:MM:SS format, which indicates the time passed since the "zero date".

The code below demonstrates the problem and its solution:

JavaScript, JScript

function TimeIntervalDemo()
{
  var Time1 = aqDateTime.Time();
  var Time2 = aqDateTime.AddTime(Time1,1,0,0,5);
  var Difference = aqDateTime.TimeInterval(Time1, Time2);
  Log.Message("The interval as DateTime: " + aqConvert.DateTimeToStr(Difference));
  // Posts "The interval as DateTime: 12/31/1899 12:00:05 AM"
  Log.Message("The interval in Days:Hours:Minutes:Seconds format: " + aqConvert.TimeIntervalToStr (Difference));
  // Posts "The interval in Days:Hours:Minutes:Seconds format: 1:00:00:05"
}

Python

def TimeIntervalDemo():
  Time1 = aqDateTime.Time()
  Time2 = aqDateTime.AddTime(Time1,1,0,0,5)
  Difference = aqDateTime.TimeInterval(Time1, Time2)
  Log.Message("The interval as DateTime: " + aqConvert.DateTimeToStr(Difference))
  # Posts "The interval as DateTime: 12/31/1899 12:00:05 AM"
  Log.Message("The interval in Days:Hours:Minutes:Seconds format: " + aqConvert.TimeIntervalToStr (Difference))
  # Posts "The interval in Days:Hours:Minutes:Seconds format: 1:00:00:05"

VBScript

Sub TimeIntervalDemo
Dim Time1, Time2, Difference
  Time1 = aqDateTime.Time()
  Time2 = aqDateTime.AddTime(Time1,1,0,0,5)
  Difference = aqDateTime.TimeInterval(Time1, Time2)
  Log.Message("The interval as DateTime: " + aqConvert.DateTimeToStr(Difference))
  ' Posts "The interval as DateTime: 12/31/1899 12:00:05 AM"
  Log.Message("The interval in Days:Hours:Minutes:Seconds format: " + aqConvert.TimeIntervalToStr (Difference))
  ' Posts "The interval in Days:Hours:Minutes:Seconds format: 1:00:00:05"
End Sub

DelphiScript

procedure TimeIntervalDemo;
var Time1, Time2, Difference;
begin
  Time1 := aqDateTime.Time();
  Time2 := aqDateTime.AddTime(Time1,1,0,0,5);
  Difference := aqDateTime.TimeInterval(Time1, Time2);
  Log.Message('The interval as DateTime: ' + aqConvert.DateTimeToStr(Difference));
  // Posts "The interval as DateTime: 12/31/1899 12:00:05 AM"
  Log.Message('The interval in Days:Hours:Minutes:Seconds format: ' + aqConvert.TimeIntervalToStr (Difference));
  // Posts "The interval in Days:Hours:Minutes:Seconds format: 1:00:00:05"
end;

C++Script, C#Script

function TimeIntervalDemo()
{
  var Time1 = aqDateTime["Time"]();
  var Time2 = aqDateTime["AddTime"](Time1,1,0,0,5);
  var Difference = aqDateTime["TimeInterval"](Time1, Time2);
  Log["Message"]("The interval as DateTime: " + aqConvert["DateTimeToStr"](Difference));
  // Posts "The interval as DateTime: 12/31/1899 12:00:05 AM"
  Log["Message"]("The interval in Days:Hours:Minutes:Seconds format: " + aqConvert["TimeIntervalToStr"](Difference));
  // Posts "The interval in Days:Hours:Minutes:Seconds format: 1:00:00:05"
}

See Also

Working With Dates
Working With Time
Compare Method
TimeIntervalToStr Method

Highlight search results