RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.TryStrToDate Function

Converts a string to a TDateTime value, with a Boolean success code.

Pascal
function TryStrToDate(const S: string; out Value: TDateTime): Boolean; overload;
function TryStrToDate(const S: string; out Value: TDateTime; const FormatSettings: TFormatSettings): Boolean; overload;
C++
Boolean TryStrToDate(const AnsiString S, TDateTime Value);
Boolean TryStrToDate(const AnsiString S, TDateTime Value, const TFormatSettings FormatSettings);

SysUtils

Call TryStrToDate to parse a string that specifies a date. If S does not contain a valid date, TryStrToDate returns false.  

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 between 0 and 99 are converted using the TwoDigitYearCenturyWindow. This value is stored either in a global variable (first form) or as a field in the FormatSettings parameter (second form) See "Currency and Date-Time Formatting Variables" for more information.  

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

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!