3
votes

I want to be able to find the difference in seconds between two TDateTime variables in Delphi 5. In the later versions of delphi there are helper functions SecondsBetween to do this. Is there a better way to do this other than rolling my own (Finding the difference of the two variables as a double then converting them to seconds)?

Thanks.

2
Welcome to 2013, dear time traveler! Just to give you a quick update: the world didn't change much in the meantime, but there are newer Delphi versions. Oh, and 2013-1999 = 14 years. Or do you need that in seconds? :) - Wouter van Nifterick

2 Answers

6
votes
Secs := Round(SecsPerMin * MinsPerHour * HoursPerDay * Abs(Time2 - Time1));
1
votes

Here goes another way of doing the same. Tested in Delphi 5

var
  Hour, Min, Sec, MSec: Word;
begin
  DecodeTime(datetime2-datetime1, Hour, Min, Sec, MSec);
end;