FullYearsBetween and leap year

I was wondering if the FullYearsBetween function works well with persons born on the 29th of February in a leap year.


It doesn’t seem to. We use start_time.FullYearsSince(dob) to calculate the age from date of birth. We get an output as -999999999 for all births on 29 Feb of any leap year. For other dates, the output is correct.

Is there a fix?

Yes, there is a problem and the problem is related to the definition.
If you were born on 2000-02-29 when do you turn 1 year old?
On the 2001-02-28? or 2001-03-01?

You can see multiple discussions on the internet, e.g. here:
or here:

Perhaps you could use the following for now:
start_time.FullYearsSince( (dob.Value.Month==2 && dob.Value.Day==29 && !(start_time.IsLeapYear)) ? new DateTime(dob.Value.Year, 2, 28) : dob)

(or a variation of it corresponding to your assumptions).

Note that both functions FullYearsBetween() and FullYearsSince() are both subject to the same issue.

Best, Sergiy

1 Like