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

# StrToTime

Convert a time string to a TDateTime value.

## Declaration

Source position: line 0

`function StrToTime(`
`const S: Shortstring`
`):TDateTime; function StrToTime(`
`const S: Ansistring`
`):TDateTime; function StrToTime(`
`const S: ShortString;`
`separator: Char`
`):TDateTime; function StrToTime(`
`const S: AnsiString;`
`separator: Char`
`):TDateTime; function StrToTime(`
`const S: string;`
`FormatSettings: TFormatSettings`
`):TDateTime; function StrToTime(`
`const S: PChar;`
`Len: Integer;`
`separator: Char = #0`
`):TDateTime;`

## Description

StrToTime converts the string S to a TDateTime time value. The time must consist of 1 to 4 digits, separated by the TimeSeparator character. If two numbers are given, they are supposed to form the hour and minutes.

## Errors

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

## See also

StrToDate |  | Convert a date string to a TDateTime value.
StrToDateTime |  | Convert a date/time string to a TDateTime value.
TimeToStr |  | Convert a TDateTime time to a string using a predefined format.

## Example

    Program Example21;

    { This program demonstrates the StrToTime function }

    Uses sysutils;

    Procedure TestStr (S : String);

    begin
      Writeln (S,' : ',TimeToStr(StrToTime(S)));
    end;

    Begin
      teststr (TimeToStr(Time));
      teststr ('12:00');
      teststr ('15:30');
      teststr ('3:30PM');
    End.

Documentation generated on: Feb 26 2014