aqConvert.StrToDateTime Method

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

Description

The StrToDateTime method converts the string S, to a Date value. The resulting value has both the date and time portions. To convert a string to a Date value having only the date or time portion, use the StrToDate and StrToTime methods respectively.

Declaration

aqConvert.StrToDateTime(S)

S [in]    Required    String    
Result Date/Time

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

S

Specifies the string to be converted.

The method recognizes dates in the following formats: "dd/mm/yy", "dd/mm/yyyy", "mm/dd/yy", "mm/dd/yyyy" and "yyyy/mm/dd". If the year is represented by two digits, the current century is assumed. The time portion is recognized if it has the "hh:mm:ss" format. Both the 24-hour and 12-hour formats can be used. Time in the 12-hour format should be followed by "AM", "PM", "am" or "pm". Leading zeros, as well as the seconds part, can be omitted.

Tip: Date and time separators coincide with regional options that are currently set on your computer. To determine the date and time separators that are currently used, or set other separator characters, in the Control Panel, open the Regional and Language Options:
  • On the Regional Options page click Customize, and then click the Date tab. The Date Separator option on this page specifies the currently used date separator.
  • On the Regional Options page click Customize, and then click the Time tab. The Time Separator option on this page specifies the currently used time separator.

If the source string does not represent a valid date and time, StrToDateTime raises an exception.

Result Value

The value of the Date type to which the specified string has been converted.

Example

The code below demonstrates how you can convert strings to date type values.

JavaScript, JScript

function StringToDate()
{
  Log.Message(aqConvert.StrToDate("06/22/2010"));
  Log.Message(aqConvert.StrToDateTime("06/22/2010 03:12 PM"));
}

/*
The routine produces the following output:
6/22/2010
6/22/2010 3:12:00 PM
*/

Python

def StringToDate():
  Log.Message(aqConvert.StrToDate("06/22/2010"))
  Log.Message(aqConvert.StrToDateTime("06/22/2010 03:12 PM"))

# The routine produces the following output:
# 6/22/2010
# 6/22/2010 3:12:00 PM

VBScript

sub StringToDate
  Log.Message(aqConvert.StrToDate("06/22/2010"))
  Log.Message(aqConvert.StrToDateTime("06/22/2010 03:12 PM"))
end sub

'The routine produces the following output:
'6/22/2010
'6/22/2010 3:12:00 PM

DelphiScript

procedure StringToDate;
begin 
  Log.Message(aqConvert.StrToDate('06/22/2010'));
  Log.Message(aqConvert.StrToDateTime('06/22/2010 03:12 PM'));
end;

{
The routine produces the following output:
6/22/2010
6/22/2010 3:12:00 PM
}

C++Script, C#Script

function StringToDate()
{
  Log["Message"](aqConvert["StrToDate"]("06/22/2010"));
  Log["Message"](aqConvert["StrToDateTime"]("06/22/2010 03:12 PM"));
}

/*
The routine produces the following output:
6/22/2010
6/22/2010 3:12:00 PM
*/

See Also

Working With Dates
aqConvert.DateTimeToStr Method
aqConvert.DateTimeToFormatStr Method
aqConvert.StrToDate Method
aqConvert.StrToTime Method

Highlight search results