When we use EncodeTime function EncodeTime(wHour, wMinute, wSecond, wMilliseconds) it is not assigning the millisec value to the Result.
We are using below to encode Date and Time
Result := EncodeDate(wYear, wMonth, wDay) +
EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
The String that we want to parse to a DateTime has value Apr 10 2008 7:21:31:460PM
but after encoding we get the output as 10/04/2008 07:21:31
.
The Result contains only HH:MM:SS
value and not millisec value.
Please let us know if there is anyway to format the values and store it in a variable along with millisec. *******************function which i am trying*************
function DateTimeParser(theString :string):TDateTime;
var wYear,wMonth,wDay,wHour, wMinute, wSecond,wMilliseconds : Word ;
Date,Month,Med :String;
Time : TDateTime;
testtime,testtime1 : TSystemTime;
var myDateTime : TDateTime;
begin
Month := Copy(theString,1,3) ;
if Month ='Jan' then wMonth := 01
else if Month ='Feb' then wMonth := 02
else if Month ='Mar' then wMonth := 03
else if Month ='Apr' then wMonth := 04
else if Month ='May' then wMonth := 05
else if Month ='Jun' then wMonth := 06
else if Month ='Jul' then wMonth := 07
else if Month ='Aug' then wMonth := 08
else if Month ='Sep' then wMonth := 09
else if Month ='Oct' then wMonth := 10
else if Month ='Nov' then wMonth := 11
else if Month ='Dec' then wMonth := 12
else ShowMessage('Not a Valid Month');
wYear := StrToInt(Copy(theString,8,4)) ;
wDay := StrToInt(Copy(theString,5,2)) ;
wHour := StrToInt(Copy(theString,13,2)) ;
wMinute := StrToInt(Copy(theString,16,2)) ;
wSecond := StrToInt(Copy(theString,19,2)) ;
wMilliseconds := StrToInt(Copy(theString,22,3)) ;
ShowMessage(IntToStr(wMilliseconds));
{if Copy(theString,25,2)= 'PM' then
wHour := wHour+12;}
Result := DateUtils.EncodeDateTime(wYear, wMonth, wDay,wHour, wMinute, wSecond, wMilliseconds);
//Result := Result+DateUtils.EncodeTime(wHour, wMinute, wSecond, wMilliseconds div 100);
myDateTime:= EncodeDate(2009,11,28)+EncodeTime(14,23,12,001);
ShowMessage(DatetimetoStr(myDateTime));
testtime1 := testtime;
Time :=EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
ShowMessage(DateTimeToStr(Result));
**********************************************************************
end;
Any ideas?
use this format HH:MM:SS.ZZZ
Cheers