I'm trying to calculate the date a person turns 18, taking into account leap years.
One might think that just adding 18 years to a date is enough:
birthDay.AddYears(18);
But if the birthday is February 29, 2000, this leads to february 28, 2018. I believe the correct answer would have to be March 1, 2018.
I found a way to do it, but I wonder if there isn't a simpler way.
birthday.AddDays(-1).AddYears(18).AddDays(1);
I would think an answer to this question would already exist on StackOverflow, but all my searches only turn up questions about calculating age on a specific date.
I don't think my question is a duplicate of Behavior of DateTime.AddYears on leap year as that one only explains why AddYears works as it does. It does not contain code to perform the calculation.
I found a quora article stating that the official date you turn 18 is different in New Sealand from the UK.