aqDateTime.Compare Method

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The aqDateTime.Compare method compares two Date/Time values.

Declaration

aqDateTime.Compare(Date1Date2)

Date1 [in]    Required    Date/Time    
Date2 [in]    Required    Date/Time    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Date1

The Date/Time value to be compared.

Date2

The Date/Time value to be compared.

Result Value

An integer number that indicates the comparison result. The possible values are:

-1 Date1 is earlier than Date2
0 Date1 is equal to Date2
1 Date1 is later than Date2

Remarks

To compare Date/Time values, this method uses the date and time formats specified by the current locale setting of Windows. If the values are specified in a format different from the current locale format, the method may return incorrect results.

Example

The code below demonstrates how you can compare different date and time values.

JavaScript, JScript

function ComparingDates()
{
  var currentDateAndTime = aqDateTime.Now();
  var currentTime = aqDateTime.Time();
  var currentDate = aqDateTime.Today();

  Log.Message(currentDateAndTime);
  Log.Message(currentTime);
  Log.Message(currentDate);

  Log.Message(aqDateTime.Compare(currentDateAndTime, currentTime));
  // 1, because currentDateAndTime is later then currentTime

  Log.Message(aqDateTime.Compare(currentDateAndTime, currentDate));
  // 1, because currentDateAndTime is later then currentDate

  Log.Message(aqDateTime.Compare(currentTime, currentDate));
  // -1, because currentTime is earlier then currentDate
}

Python

def ComparingDates():
  currentDateAndTime = aqDateTime.Now()
  currentTime = aqDateTime.Time()
  currentDate = aqDateTime.Today()
  Log.Message(currentDateAndTime)
  Log.Message(currentTime)
  Log.Message(currentDate)
  Log.Message(aqDateTime.Compare(currentDateAndTime, currentTime))
  # 1, because currentDateAndTime is later then currentTime
  Log.Message(aqDateTime.Compare(currentDateAndTime, currentDate));
  # 1, because currentDateAndTime is later then currentDate
  Log.Message(aqDateTime.Compare(currentTime, currentDate));
  # -1, because currentTime is earlier then currentDate

VBScript

Sub ComparingDates
  Dim currentDateAndTime, currentTime, currentDate

  currentDateAndTime = aqDateTime.Now
  currentTime = aqDateTime.Time
  currentDate = aqDateTime.Today

  Log.Message(currentDateAndTime)
  Log.Message(currentTime)
  Log.Message(currentDate)

  Log.Message(aqDateTime.Compare(currentDateAndTime, currentTime))
  ' 1, because currentDateAndTime is later then currentTime

  Log.Message(aqDateTime.Compare(currentDateAndTime, currentDate))
  ' 1, because currentDateAndTime is later then currentDate

  Log.Message(aqDateTime.Compare(currentTime, currentDate))
  ' -1, because currentTime is earlier then currentDate
End Sub

DelphiScript

procedure ComparingDates;
var currentDateAndTime, currentTime, currentDate;
begin
  currentDateAndTime := aqDateTime.Now;
  currentTime := aqDateTime.Time;
  currentDate := aqDateTime.Today;

  Log.Message(currentDateAndTime);
  Log.Message(currentTime);
  Log.Message(currentDate);

  Log.Message(aqDateTime.Compare(currentDateAndTime, currentTime));
  // 1, because currentDateAndTime is later then currentTime

  Log.Message(aqDateTime.Compare(currentDateAndTime, currentDate));
  // 1, because currentDateAndTime is later then currentDate

  Log.Message(aqDateTime.Compare(currentTime, currentDate));
  // -1, because currentTime is earlier then currentDate
end;

C++Script, C#Script

function ComparingDates()
{
  var currentDateAndTime = aqDateTime["Now"]();
  var currentTime = aqDateTime["Time"]();
  var currentDate = aqDateTime["Today"]();

  Log["Message"](currentDateAndTime);
  Log["Message"](currentTime);
  Log["Message"](currentDate);

  Log["Message"](aqDateTime["Compare"](currentDateAndTime, currentTime));
  // 1, because currentDateAndTime is later then currentTime

  Log["Message"](aqDateTime["Compare"](currentDateAndTime, currentDate));
  // 1, because currentDateAndTime is later then currentDate

  Log["Message"](aqDateTime["Compare"](currentTime, currentDate));
  // -1, because currentTime is earlier then currentDate
}

See Also

Working With Dates
Working With Time
aqDateTime.TimeInterval Method

Highlight search results