function difftime(time1, time2: tDateTime): Word;
var
Year1, Month1, Day1, Hour1, Min1, Sec1, MSec1: Word;
Year2, Month2, Day2, Hour2, Min2, Sec2, MSec2: Word;
begin
DecodeDate(time1, Year1, Month1, Day1);
DecodeTime(time1, Hour1, Min1, Sec1, MSec1);
DecodeDate(time2, Year2, Month2, Day2);
DecodeTime(time2, Hour2, Min2, Sec2, MSec2);
result := (day2 - day1) * 24 * 60 * 60 + (hour2 - hour1) * 3600 + (min2 - min1)
* 60 + (sec2 - sec1)
+ (month2 - month1) * 30 * 24 * 3600;
end;