Age In Years - CSharp System

CSharp examples for System:DateTime Year

Description

Age In Years

Demo Code


using System;/*from w w w. ja va2s . c  o m*/

public class Main{
        public static int AgeInYears(DateTime birthdate)
        {
            int years = DateTime.Now.Year - birthdate.Year;
            if (DateTime.Now.Month < birthdate.Month || (DateTime.Now.Month == birthdate.Month && DateTime.Now.Day < birthdate.Day))
                years--;

            return years;
        }
}

Related Tutorials