aqConvert.DateTimeToStr Method

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

Description

The DateTimeToStr method converts a date/time value to a string according to the user’s locale settings. The date part is converted using the short date format.

To customize the format of a date/time value, for example, get a string containing only the date or time part of the value, use the DateTimeToFormatStr method.

Declaration

aqConvert.DateTimeToStr(D)

D [in]    Required    Date/Time    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

D

The date/time value to be converted to a string. If the date part of the value is missing, it is assumed to be the “zero date”, December 30, 1899. If the time part is missing, it is not included in the resulting string.

Result Value

A string that contains the specified date and time.

Example

The following example demonstrates how you can convert date and/or time values to strings.

JavaScript, JScript

function DateTimeToStrSample()
{
  var dt;

  dt = aqDateTime.SetDateTimeElements(2010, 1, 1, 10, 0, 0); // both date and time
  Log.Message(aqConvert.DateTimeToStr(dt));

  dt = aqDateTime.SetDateElements(2010, 1, 1); // date only
  Log.Message(aqConvert.DateTimeToStr(dt));

  dt = aqDateTime.SetTimeElements(10, 0, 0); // time only
  Log.Message(aqConvert.DateTimeToStr(dt));
}

/*
The routine produces the following output for the US English locale:

1/1/2010 10:00:00 AM
1/1/2010
12/30/1899 10:00:00 AM
*/

Python

def DateTimeToStrSample():
  dt = aqDateTime.SetDateTimeElements(2010, 1, 1, 10, 0, 0) # both date and time
  Log.Message(aqConvert.DateTimeToStr(dt))
  dt = aqDateTime.SetDateElements(2010, 1, 1) # date only
  Log.Message(aqConvert.DateTimeToStr(dt))
  dt = aqDateTime.SetTimeElements(10, 0, 0) # time only
  Log.Message(aqConvert.DateTimeToStr(dt))

# The routine produces the following output for the US English locale:
# 1/1/2010 10:00:00 AM
# 1/1/2010
# 12/30/1899 10:00:00 AM

VBScript

Sub DateTimeToStrSample
  Dim dt

  dt = aqDateTime.SetDateTimeElements(2010, 1, 1, 10, 0, 0) ' both date and time
  Log.Message aqConvert.DateTimeToStr(dt)

  dt = aqDateTime.SetDateElements(2010, 1, 1) ' date only
  Log.Message aqConvert.DateTimeToStr(dt)

  dt = aqDateTime.SetTimeElements(10, 0, 0) ' time only
  Log.Message aqConvert.DateTimeToStr(dt)
End Sub

' The routine produces the following output for the US English locale:

' 1/1/2010 10:00:00 AM
' 1/1/2010
' 12/30/1899 10:00:00 AM

DelphiScript

procedure DateTimeToStrSample;
var dt;
begin
  dt := aqDateTime.SetDateTimeElements(2010, 1, 1, 10, 0, 0); // both date and time
  Log.Message(aqConvert.DateTimeToStr(dt));

  dt := aqDateTime.SetDateElements(2010, 1, 1); // date only
  Log.Message(aqConvert.DateTimeToStr(dt));

  dt := aqDateTime.SetTimeElements(10, 0, 0); // time only
  Log.Message(aqConvert.DateTimeToStr(dt));
end;

{
The routine produces the following output for the US English locale:

1/1/2010 10:00:00 AM
1/1/2010
12/30/1899 10:00:00 AM
}

C++Script, C#Script

function DateTimeToStrSample()
{
  var dt;

  dt = aqDateTime["SetDateTimeElements"](2010, 1, 1, 10, 0, 0); // both date and time
  Log["Message"](aqConvert["DateTimeToStr"](dt));

  dt = aqDateTime["SetDateElements"](2010, 1, 1); // date only
  Log["Message"](aqConvert["DateTimeToStr"](dt));

  dt = aqDateTime["SetTimeElements"](10, 0, 0); // time only
  Log["Message"](aqConvert["DateTimeToStr"](dt));
}

/*
The routine produces the following output for the US English locale:

1/1/2010 10:00:00 AM
1/1/2010
12/30/1899 10:00:00 AM
*/

See Also

Working With Dates
Working With Time
aqDateTime Object
aqConvert.DateTimeToFormatStr Method
aqConvert.StrToDateTime Method
aqConvert.StrToDate Method
aqConvert.StrToTime Method

Highlight search results