c# - what is the simplest and correct way to calculate age? -


possible duplicate:
how calculate someone's age in c#?

hi, simple question. need calculate age , allow people 21. use timespan? given inputting date need check if >=21.

suggestions?

the easiest way isn't calculate age - it's see whether birthday after limit:

datetime twentyoneyearsago = datetime.today.addyears(-21);  if (birthdate > twentyoneyearsago) {     // sorry, you're young } 

note on february 29th on leap year, addyears return february 28th on relevant earlier year. that's want in case, if user has entered actual date.


Comments

Popular posts from this blog

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

xslt - Umbraco and EXSLT sets do not work -

php - How can I merge Nodes & Webform Submissions into instances of one general Content Type in Drupal 6? -