HOW DO I CALCULATE SOMEONE'S AGE IN C#?

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
C# 
C#
 1601  View(s)
Ratings:
Rate this:
Given a DateTime representing a person's birthday, how do I calculate their age?
  1. Alex Leblois

    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--;

Answer

NEWSLETTER

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