age calculation in C#

Total Post:4

Points:28
C# 
C#
 2597  View(s)
Ratings:
Rate this:

Hi Expert!

I'm working on windows application with C# and I want to calculate age (year) from today's date. Please help me!

Thanks in advance

  1. Post:604

    Points:4228
    Re: age calculation in C#

    Hi Benjamin Richards!

      You can use this way!

      // Get current date
      DateTime today = DateTime.Today;
      // Assing given date
      DateTime bday = DateTime.Parse("12/05/1986 12:00:00 AM");
      // Get difference between two date
      int age = today.Year - bday.Year;

      Modified On Feb-04-2013 05:55:08 AM

Answer