[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'sysutils' (#rtl)

StrToDate

Convert a date string to a TDateTime value.

Declaration

Source position: datih.inc line 140

function StrToDate(

  const S: ShortString

):TDateTime;

function StrToDate(

  const S: Ansistring

):TDateTime;

function StrToDate(

  const S: ShortString;

  separator: Char

):TDateTime;

function StrToDate(

  const S: AnsiString;

  separator: Char

):TDateTime;

function StrToDate(

  const S: string;

  FormatSettings: TFormatSettings

):TDateTime;

function StrToDate(

  const S: ShortString;

  const useformat: string;

  separator: Char = #0

):TDateTime;

function StrToDate(

  const S: AnsiString;

  const useformat: string;

  separator: Char = #0

):TDateTime;

function StrToDate(

  const S: PChar;

  Len: Integer;

  const useformat: string;

  separator: Char = #0

):TDateTime;

Description

StrToDate converts the string S to a TDateTime date value. The Date must consist of 1 to three digits, separated by the DateSeparator character. If two numbers are given, they are supposed to form the day and month of the current year. If only one number is given, it is supposed to represent the day of the current month. (This is not supported in Delphi)

The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the ShortDateFormat variable.

Errors

On error (e.g. an invalid date or invalid character), an EConvertError exception is raised.

See also

StrToTime

  

Convert a time string to a TDateTime value.

DateToStr

  

Converts a TDateTime value to a date string with a predefined format.

TimeToStr

  

Convert a TDateTime time to a string using a predefined format.

EConvertError

  

Conversion error.

Example

Program Example19;

{ This program demonstrates the StrToDate function }

Uses sysutils;

Procedure TestStr (S : String);

begin
  Writeln (S,' : ',DateToStr(StrToDate(S)));
end;

Begin

  Writeln ('ShortDateFormat ',ShortDateFormat);
  TestStr(DateTimeToStr(Date));
  TestStr('05'+DateSeparator+'05'+DateSeparator+'1999');
  TestStr('5'+DateSeparator+'5');
  TestStr('5');
End.

Documentation generated on: Jun 22 2020