CalendarMonthsApart Function
Returns the Number of Calendar Months between DT2 and DT1.

Unit
QESBPCSDateTime

Declaration
Function CalendarMonthsApart(const DT1, DT2: TDateTime): LongInt;

Description
If result is 0 then they are in within the same Calendar Month, if result is negative then DT2 occurs in a Calendar Month before DT1.

Parameters
DT1 First Date/Time to process.
DT2 Second Date/Time to process.

Category
Date/Time Arithmetic Routines
Week Based Arithmetic Routines

Implementation

function CalendarMonthsApart (const DT1, DT2: TDateTime): Integer;
var
     D1, M1, Y1, D2, M2, Y2: Integer;
begin
     OptDecodeDateI (DT1, Y1, M1, D1);
     OptDecodeDateI (DT2, Y2, M2, D2);
     if Y1 = Y2 then
          Result := M2 - M1
     else if Y2 > Y1 then
          Result := (12 - M1) + (Y2 - (Y1 + 1)) * 12 + M2
     else
          Result := - ((12 - M2) + (Y1 - (Y2 + 1)) * 12 + M1)
End;


HTML generated by Time2HELP
http://www.time2help.com