Calculate Age using C#

CSharp · Console

/Program.cs

using System;

public class Program
{
	public static void Main()
	{
		DateTime dob = Convert.ToDateTime("26 Aug 1989");
		DateTime PresentYear = DateTime.Now;
		TimeSpan ts = PresentYear - dob;
		DateTime Age = DateTime.MinValue.AddDays(ts.Days);
		Console.WriteLine(string.Format(" {0} Years {1} Month {2} Days", Age.Year - 1, Age.Month - 1, Age.Day - 1));
		Console.WriteLine(string.Format(" {0} Years {1} Month", Age.Year - 1, Age.Month - 1));
		Console.WriteLine(string.Format(" {0} Years", Age.Year - 1));
	}
}
;