Saltar al contenido principal

StrToDate

Converts a string to a TDateTime value.

Structure

StrToDate(string): TDateTime;

Parameters

Return Value

Description

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. The order for month, day, and year is determined by the ShortDateFormat global variable--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 global variable. If TwoDigitYearCenturyWindow is 0, year values between 0 and 99 are assumed to be in the current century. If TwoDigitYearCenturyWindow is greater than 0, its value is subtracted from the current year to determine the 'pivot'; years on or after the pivot are kept in the current century, while years prior to the pivot are moved to the next century. For example:

Current year TwoDigitYear CenturyWindow Pivot date =mm/dd/03 date =mm/dd/50 date =mm/dd/68

1998 0 1900 1903 1950 1968

2002 0 2000 2003 2050 2068

1998 50 1948 2003 1950 1968

2000 50 1950 2003 1950 1968

2002 50 1952 2003 2050 1968

2020 50 1970 2003 2050 2068

2020 10 2010 2103 2050 2068

Note

The format of the date string varies when the values of date/time formatting variables are changed. |