From: grahamharris@hotmail.com (Graham Harris) Newsgroups: borland.public.delphi.objectpascal Subject: Re: StrToDate and 'mmm' formats - WHY NOT??? Date: Sat, 23 Feb 2002 15:57:36 GMT Message-ID: <3c77baed.14894807@forums.borland.com> References: <3c776652$1_1@dnews> X-Newsreader: Forte Free Agent 1.21/32.243 NNTP-Posting-Host: 195.147.232.98 X-Trace: dnews 1014479859 195.147.232.98 (23 Feb 2002 07:57:39 -0800) Lines: 78 Path: dnews Xref: dnews borland.public.delphi.objectpascal:229900 Try these for size: function ISODateStrToDateTime(const Date: AnsiString): TDateTime; var D, M, Y: Word; begin Result := 0; if not IsNumeric(Date) then Exit; if not CheckDateFormat(Date) then Exit; { If Time = "" then that means that we have been passed a blank dowm message from an HL7 message. Which CheckDateFormat considers valid. } if Date = '""' then Exit; Y := StrToInt(Copy(Date, 1, 4)); M := StrToInt(Copy(Date, 5, 2)); D := StrToInt(Copy(Date, 7, 2)); Result := EncodeDate(Y, M, D); end; //------------------------------------------------------------------------------ function ISODateTimeStrToDateTime(const DateTime: AnsiString): TDateTime; begin Result := ISODateStrToDateTime(Copy(DateTime, 1, 8)) + ISODateTimeStrToDateTime(Copy(DateTime, 9, Length(DateTime))); end; //------------------------------------------------------------------------------ function ISOTimeStrToTime(const Time: AnsiString): TDateTime; var H, M, S, Ms: Word; begin Result := 0; if not IsNumeric(Time) then Exit; if not CheckTimeFormat(Time) then Exit; { If Time = "" then that means that we have been passed a blank down message from an HL7 message. Which CheckTimeFormat considers valid. } if Time = '""' then Exit; H := StrToInt(Copy(Time, 1, 2)); M := StrToInt(Copy(Time, 3, 2)); if Length(Time) < 6 then S := 0 else S := StrToInt(Copy(Time, 5, 2)); if Length(Time) <= 6 then Ms := 0 else Ms := StrToInt(Copy(Time, 7, Length(Time))); Result := EncodeTime(H, M, S, Ms); end; Note you must pass these functions the date time strings in the following format: yyyymmddhhnnss with miliseconds from position 14 in the string. As to converting your date string to the above format I will need a little to work out a routine to convert 13 Feb 2002 to 20020213. Pleas also for sanity's sake I am assuming the year is 4 digits long! I will hopefully have a code sample for you later on today. HTH Graham Harris