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.

2 Likes

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:
https://www.quora.com/If-youre-born-on-February-29th-when-do-you-legally-turn-one-year-older
or here:
https://www.quora.com/If-someone-is-born-on-February-29th-due-to-a-leap-year-does-the-government-use-February-28th-or-March-1st-for-legal-milestones-ie-legally-driving-legally-drinking-etc

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