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

Total Post:135

Points:947
C# 
C#
 1929  View(s)
Ratings:
Rate this:
Given a DateTime representing a person's birthday, how do I calculate their age?
  1. Post:67

    Points:471
    Re: How do I calculate someone's age in C#?

    Hi Chintoo,

    You can calculate the age like this:
    DateTime today = DateTime.Today;
    int age = today.Year - bday.Year;
    if (bday > today.AddYears(-age)) age--;

      Modified On Apr-04-2018 01:09:19 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!