1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
| function GetDateDifference(const Date1, Date2: TDate): string; type PDayTable = ^TDayTable; TDayTable = array[1..12] of Word;
const MonthDays: array [Boolean] of TDayTable = ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31), (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)); var D1, M1, Y1: Word; D2, M2, Y2: Word; D3, M3, Y3: Word; begin if Date1 < Date2 then begin DecodeDate(Date1, Y1, M1, D1); DecodeDate(Date2, Y2, M2, D2); end else begin DecodeDate(Date1, Y1, M1, D1); DecodeDate(Date2, Y2, M2, D2); end;
D3 := 0; M3 := 0; Y3 := 0;
if Y1 <> Y2 then begin Y3 := Y2 - Y1; if M1 > M2 then Y3 := Y3 - 1; end;
if M1 <> M2 then begin if M1 > M2 then begin M3 := (StrToInt('1' + IntToStr(M2))) - M1 + 1;
if D1 < D2 then M3 := M3 + 1; end else M3 := M2 - M1; end;
if D1 <> D2 then begin if D1 < D2 then D3 := D2 - D1 else D3 := (MonthDays[(M3 = 2) and (Y3 mod 4 = 0) and ((Y3 mod 100 <> 0) or (Y3 mod 400 = 0)), M3]) - D1 + 1; end;
Result := Format('%d.%d.%d', [D3, M3, Y3]); end; |