function ISOWeekNosApart (DT1, DT2: TDateTime): Int64;
var
W1, W2: Integer;
I, Y1, Y2: Word;
Negative: Boolean;
DTHold: TDateTime;
begin
Negative := Int (DT2) < Int (DT1);
if Negative then
begin
DTHold := DT1;
DT1 := DT2;
DT2 := DTHold;
end;
// Now DT1 <= DT2
Date2ISOWeekNo (DT1, W1, Y1);
Date2ISOWeekNo (DT2, W2, Y2);
if Y1 = Y2 then
Result := W2 - W1
else
begin
Result := ISOWeeksInYear (Y1) - W1 + W2;
for I := Y1 + 1 to Y2 - 1 do
Result := Result + ISOWeeksInYear (I)
end;
if Negative then
Result := -1 * Result;
End; |