DigitStr2Date Function
Converts a string containing a Date into a DateTime.

Unit
QESBPCSDateTime

Declaration
Function DigitStr2Date(const DateStr: string): TDateTime;

Description
Assumes formatting in the form of 'YYYYMMDD'. If String has length less then 8 or is an invalid Date then Exception is raised.

Parameters
DateStr The String to convert.

Category
Date/Time Conversion Routines

Implementation

function DigitStr2Date (const DateStr: string): TDateTime;
var
     Day, Month, Year: Integer;
     S: string;
begin
     if Length (DateStr) < 8 then
          raise EConvertError.Create (rsInvalidDate);

     S := Trim (DateStr);
     Year := Str2Int (LeftStr (S, 4));
     Month := Str2Int (Copy (S, 5, 2));
     Day := Str2Int (Copy (S, 7, 2));
     Result := OptEncodeDateI (Year, Month, Day);
End;


HTML generated by Time2HELP
http://www.time2help.com