procedure TForm1.Button1Click(Sender: TObject);
var
FS: TFormatSettings;
d1, d2: TDateTime;
begin
d1 := EncodeDateTime(2021, 01, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 02, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 03, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 04, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 05, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 06, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 07, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 08, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 09, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 10, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 11, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
d1 := EncodeDateTime(2021, 12, 01, 00, 00, 01, 0001);
d2 := EncodeDateTime(2021, 12, 31, 00, 00, 01, 0001);
Memo1.Lines.Add('From: ' + DateToStr(d1) + ' To: ' + DateToStr(d2) + ' is ' + IntToStr(MonthsBetween(d1, d2, True)));
end;