aqConvert.StrToDate Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

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

Declaration

aqConvert.StrToDate(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". Leading zeros can be omitted. If the year is represented by two digits, the current century is assumed.

Tip: Date separator coincides with regional options that are currently set on your computer. To determine the date separator that is currently used, or set another separator character in the Control Panel, open the Regional and Language Options. On the Regional Options page click Customize then click the Date tab. The Date Separator option on this page specifies the currently used date separator.

If the source string does not represent a valid date, StrToDate raises an exception.

Result Value

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

Remarks

If the two-digit year format is used in your Windows operating system, there can be ambiguity in the year presentation. For example, 19 can stand for 1919 and 2019. To avoid confusion, for years of other centuries, this method will always return the year part in the four-digit format.

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
DateTimeToStr Method
DateTimeToFormatStr Method
StrToDateTime Method
StrToTime Method

Highlight search results