Home How do I calculate someone's age in C#?

# How do I calculate someone's age in C#?

user9045
1#
user9045 Published in September 21, 2018, 2:58 am

Given a DateTime representing a person's birthday, how do I calculate their age in years?

## locked by Yvette Colomb♦Apr 21 at 17:49

This post has been locked while disputes about its content are being resolved. For more info visit meta.

• what all of the answers so far have missed is that it depends where the person was born and where they are right now. – Yaur May 21 '11 at 7:34
• @Yaur: Just convert the time of now + birth into GMT/UTC, age is only a relative value, hence timezones are irrelevant. For determining the user's current timezone, you can use GeoLocating. – Stefan Steiger Oct 3 '11 at 10:20
• Why not consider [Julian Date][1]? [1]: stackoverflow.com/questions/7103064/… – Muhammad Hewedy Oct 5 '13 at 13:32
• If we're taking into consideration @Yaur 's suggestion of cross-timezone calculations, should Day Light Saving Time affect the calculation in any manner? – DDM Jul 11 '15 at 3:42
• No one has considered leap years? or checking the month? – Crash Override Jun 15 '17 at 10:06