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
Post a Comment