aqDateTime.Now Method

Applies to TestComplete 15.45, last modified on December 01, 2022

Description

Use the aqDateTime.Now method to get the current date and time. To get only the current date or only the current time, use the Today and Time methods respectively.

Declaration

aqDateTime.Now()

Result Date/Time

Applies To

The method is applied to the following object:

Result Value

A Date/Time value that holds the current date and time.

In JavaScript, JScript, Python or DelphiScript, if you try to output the date and time returned by the Now method as a string, conversion takes place and the date and time are output in the native format for the selected language (day/month/date/time/year in JavaScript, JScript and DelphiScript, year/month/day/time in Python). For example, this occurs if you use the following code to post the current date and time to the test log:

JavaScript, JScript

function Test()
{
  Log.Message("Now:" + aqDateTime.Now());
}

Python

def Test():
  Log.Message("Now: " + str(aqDateTime.Now()))

VBScript

Sub Test
  Log.Message("Now: " & aqDateTime.Now())
end sub

DelphiScript

function Test;
begin
  Log.Message('Now: ' + aqDateTime.Now);
end;

C++Script, C#Script

function Test()
{
  Log["Message"]("Now:" + aqDateTime["Now"]());
}

To avoid such a conversion, you need to explicitly specify the format in which time should be displayed. For example, you can use the following code:

JavaScript, JScript

function Test()
{
  Log.Message("Now: " + aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%m/%d/%y %H:%M:%S"));
}

Python

def Test2():
  Log.Message("Now: " + aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%m/%d/%y %H:%M:%S"))

VBScript

Sub Test
  Log.Message("Now: " & aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%m/%d/%y %H:%M:%S"))
end sub

DelphiScript

function Test;
begin
  Log.Message('Now: ' + aqConvert.DateTimeToFormatStr(aqDateTime.Now(), '%m/%d/%y %H:%M:%S'));
end;

C++Script, C#Script

function Test()
{
  Log["Message"]("Now:" + aqConvert["DateTimeToFormatStr"](aqDateTime["Now"](), "%m/%d/%y %H:%M:%S"));
}

Example

The code below demonstrates how you can use the Now method in your script:

JavaScript, JScript

function ComparingDates()
{
  var dateTimeTimeout = aqDateTime.AddSeconds(aqDateTime.Now(), 15);
    
  while (aqDateTime.Compare(aqDateTime.Now(), dateTimeTimeout) < 1)
  {
    Delay(500);
  }
  
}

Python

def ComparingDates():
  dateTimeTimeout = aqDateTime.AddSeconds(aqDateTime.Now(), 15)
  while (aqDateTime.Compare(aqDateTime.Now(), dateTimeTimeout) < 1):
    Delay(500)

VBScript

Sub ComparingDates
  Dim dateTimeTimeout
  
  dateTimeTimeout = aqDateTime.AddSeconds(aqDateTime.Now(), 15)
  While aqDateTime.Compare(aqDateTime.Now(), dateTimeTimeout) < 1
    Delay(500)
  WEnd
  
End Sub

DelphiScript

procedure ComparingDates();
var dateTimeTimeout;
begin
 dateTimeTimeout := aqDateTime.AddSeconds(aqDateTime.Now(), 15);
    
  while (aqDateTime.Compare(aqDateTime.Now(), dateTimeTimeout) < 1) do
  begin
    Delay(500);
  end;
  
end;

C++Script, C#Script

function ComparingDates()
{
  var dateTimeTimeout = aqDateTime["AddSeconds"](aqDateTime["Now"](), 15);
    
  while (aqDateTime["Compare"](aqDateTime["Now"](), dateTimeTimeout) < 1)
  {
    Delay(500);
  }
  
};

See Also

Working With Dates
Working With Time
Today Method
Time Method

Highlight search results