Mega Code Archive

 
Categories / Delphi / Examples
 

How to use TimeStamp for our application

Title: How to use TimeStamp for our application Question: How to use TimeStamp for our application Answer: Here're the functions 1. Count Days between Date1 and Date2 -(1/1/01 - 4/4/01) = 94 Days If you use DecodeDate, it'll be hardway for you. In this case we can use TimeStamp for ease. Example : Function TForm1.CountDays(d1,d2:TDate):integer; var xD1,xD2:longint; begin xD1:=DateTimeToTimeStamp(d1).date; xD2:=DateTimeToTimeStamp(d2).date; Result:=(XD2-XD1)+1; end; 2. Count Hours between Time1 And Time2 -(01:00 AM-04:30 AM) = 4.5 Hours Example : Function TForm1.CountHour(t1,t2:TTime):single; var xT1,xT2:single; begin xT1:=DateTimeToTimeStamp(t1).time; xT2:=DateTimeToTimeStamp(t2).time; if xT1xT2 then if xT2 xT1:=xT1-43200000; xT2:=xT2+43200000; Result:=abs((xT1-XT2)/3600000); end else result:=abs(12-(xT1-XT2)/3600000) else Result:=abs(((xT1-XT2)/3600000)); end;