Calculate Age - CSharp System

CSharp examples for System:DateTime Calculate

Description

Calculate Age

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Linq;
using System.Collections.Generic;
using System;//from www  .  j  av  a2s.c om

public class Main{
        public static int CalculateAge(DateTime source, DateTime birthday)
        {
            int anos = source.Year - birthday.Year;
            if (source.Month < birthday.Month
                || (source.Month == birthday.Month
                && source.Day < birthday.Day))
                anos--;
            return anos;
        }
}

Related Tutorials