How do I calculate someone's age in C#?
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
Given a DateTime representing their birthday, how do I calculate someone's age?
This question and answers originated from www.stackoverflow.com
Question by Jeff Atwood (7/31/2008 11:40:59 PM)
Answer |
For some reason Jeff's code didn't seem simple enough. To me this seems simpler and easier to understand:
DateTime now = DateTime.Today;
int age = now.Year - bday.Year;
if (bday > now.AddYears(-age)) age--;
Answer by Mike Polen
Find More Answers