Algorithm Math Delphi

Title: DaysBetweenInt
Question: When you use he DAYBETWEEN function in Delphi you don't get the actual numbers of days between 2 dates. You get a number thas is one less and a fraction of a day. This difference occurs because you a use time time fraction in a TDateTime variable. The (very simple) method below solves this problem:
Answer:
Procedure DaysBetweenInt(Dt1, Dt2 : TDateTime ) : Integer;
VAR
MyDt1, MyDt2 : TDate;
BEGIN
MyDt1 := StrtoDate(DatetoStr(Dt1));
MyDt2 := StrtoDate(DatetoStr(Dt2));
//
// Both Dtn Variables are first converted to STRING-types and
// then converted back to TDateTime (but this time the
// min-sec-msec is set to 00:00:000 -
//
// Now do the aritmetics
//
Result := Trunc(MyDt1 - MyDt2);
END;
NOTE
Remenber to use the correct
DateSeparator and
ShortDateFormat / LongDateformat
Enjoy
KRIS