Calc Age - CSharp System

CSharp examples for System:DateTime Calculate

Description

Calc Age

Demo Code


using System.Windows;
using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Globalization;
using System.Collections.Generic;
using System;/*w  w  w . jav a 2s .  c o  m*/
using Asclepius.AppPages.Models;

public class Main{
        public static int CalcAge(DateTime reference, DateTime birthDate)
        {
            DateTime now = reference;
            int age = now.Year - birthDate.Year;
            if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day)) age--;
            return age;
        }
}

Related Tutorials