Delphi Examples: DbiTimeDecode

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiTimeDecode

Return to chapter overview

Decode a TIME variable into hour, minutes, and seconds.

This example decodes Hour, Minute, and Seconds fields from a the TIME value specified in the TimeT parameter and returns the time value as a string.

This example uses the following input:

 TimeStr := fDbiTimeDecode(MyTime, MyHour, MyMin, MyMilSec);

 

The function is:

function fDbiTimeDecode(TimeT: Time; var iHour, iMin, iSec: Word): String;

begin

 Check(DbiTimeDecode(TimeT, iHour, iMin, iSec));

 iSec := iSec div 1000;

 SetLength(Result, 12);

if (iHour < 12) then begin

  if (iHour = 0) then

     iHour := 12;

   Result := Format('%d:%d:%d AM', [iHour, iMin, iSec]);

end

else begin

  if (iHour > 12) then

     dec(iHour, 12);

   Result := Format('%d:%d:%d PM', [iHour, iMin, iSec]);

end;

 SetLength(Result, StrLen(PChar(Result)));

end;