Con fuerza bruta he hecho esto...
Código Delphi
[-]
procedure TFMPruebas.TButtDaysBetweenClick(Sender: TObject);
var
F1, F2 : TDateTime;
function Dias29FebreroEntreFechas(ANow, AThen: TDateTime) : integer;
var
aYear, aMonth, aDay: Word;
T : TDateTime;
begin
Result := 0;
if (ANow > AThen) then
begin
T := AThen;
AThen := ANow;
ANow := T;
end;
while (ANow < AThen) do
begin
DecodeDate(ANow, aYear, aMonth, aDay);
if ((aMonth = 2) and (aDay = 29)) then
inc(Result);
ANow := IncDay(ANow);
end;
end;
begin
F1 := EncodeDate(2017, 11, 29);
F2 := EncodeDate(2020, 11, 29);
Log(Format('DaysBetween(%s, %s) = %d (- %d) = %d', [DateToStr(F2), DateToStr(F1), DaysBetween(F2, F1), Dias29FebreroEntreFechas(F2, F1), DaysBetween(F2, F1) - Dias29FebreroEntreFechas(F2, F1)]));
F1 := EncodeDate(2017, 11, 29);
F2 := EncodeDate(2020, 02, 28);
Log(Format('DaysBetween(%s, %s) = %d (- %d) = %d', [DateToStr(F2), DateToStr(F1), DaysBetween(F2, F1), Dias29FebreroEntreFechas(F2, F1), DaysBetween(F2, F1) - Dias29FebreroEntreFechas(F2, F1)]));
F1 := EncodeDate(2020, 01, 01);
F2 := EncodeDate(2020, 02, 28);
Log(Format('DaysBetween(%s, %s) = %d (- %d) = %d', [DateToStr(F2), DateToStr(F1), DaysBetween(F2, F1), Dias29FebreroEntreFechas(F2, F1), DaysBetween(F2, F1) - Dias29FebreroEntreFechas(F2, F1)]));
F1 := EncodeDate(2020, 01, 01);
F2 := EncodeDate(2020, 03, 01);
Log(Format('DaysBetween(%s, %s) = %d (- %d) = %d', [DateToStr(F2), DateToStr(F1), DaysBetween(F2, F1), Dias29FebreroEntreFechas(F2, F1), DaysBetween(F2, F1) - Dias29FebreroEntreFechas(F2, F1)]));
end;
Código Delphi
[-]
[2017-11-29 17:08:23.591] DaysBetween(29/11/2020, 29/11/2017) = 1096 (- 1) = 1095
[2017-11-29 17:08:23.591] DaysBetween(28/02/2020, 29/11/2017) = 821 (- 0) = 821
[2017-11-29 17:08:23.591] DaysBetween(28/02/2020, 01/01/2020) = 58 (- 0) = 58
[2017-11-29 17:08:23.591] DaysBetween(01/03/2020, 01/01/2020) = 60 (- 1) = 59