System.SysUtils.StrToDate

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function StrToDate(const S: string): TDateTime;
function StrToDate(const S: string;
const AFormatSettings: TFormatSettings): TDateTime;

C++

extern DELPHI_PACKAGE System::TDateTime __fastcall StrToDate(const System::UnicodeString S)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.SysUtils.pas
System.SysUtils.hpp
System.SysUtils System.SysUtils

Description

Converts a string to a TDateTime value.

Call StrToDate to parse a string that specifies a date. If S does not contain a valid date, StrToDate raises an EConvertError exception.

S must consist of two or three numbers, separated by the character defined by the DateSeparator global variable or its TFormatSettings equivalent. The order for month, day, and year is determined by the ShortDateFormat global variable or its TFormatSettings equivalent--possible combinations are m/d/y, d/m/y, and y/m/d.

If S contains only two numbers, it is interpreted as a date (m/d or d/m) in the current year.

Year values from 0 through 99 are converted using TwoDigitYearCenturyWindow. This value is stored either in a global variable (first form) or as a field in the AFormatSettings parameter (second form). See "Currency and Date-Time Formatting Variables" for more information.

The first form of StrToDate is not thread-safe, because it uses localization information contained in global variables. The second form of StrToDate, which is thread-safe, refers to localization information contained in the AFormatSettings parameter. Before calling the thread-safe form of StrToDate, you must populate AFormatSettings with localization information. To populate AFormatSettings with a set of default locale values, call TFormatSettings.Create.

See Also

Code Examples