Format: mm/dd/yyyy

DOB: 05/01/1994

Today: 10/12/2015

I tried many Methods to Solve this issue, but all of them wasn't right cause it uses the DateTime and TimeSpan. So! I created my own Method and tested it.

My Answer: 5/11/0021 "

**Right **Answer".

.Net Answer: 6/13/0022 "

**Wrong **Answer".

DateTime CalculateAge(DateTime DateOfBirth)
{
var now = DateTime.Now;
var currentMonth = DateOfBirth.Month;
int years = 0, months = 0,
days = (now - DateOfBirth).Days;
while (days >= MonthDays(currentMonth))
{
months++; days -= MonthDays(currentMonth);
if (months == 12)
{ years++; months = 0; }
if (currentMonth == 12)
currentMonth = 0;
currentMonth++;
}
var daysToRemove = Convert.ToInt32(years / 4);
var editedDate = new DateTime(now.Year, now.Month, days)
.AddDays(-daysToRemove);
return new DateTime((editedDate.Year - now.Year) + years,
(editedDate.Month - now.Month) + months, editedDate.Day);
}
int MonthDays(int Month)
{
switch (Month)
{ case 1: return 31;
case 2: return 28;
case 3: return 31;
case 4: return 30;
case 5: return 31;
case 6: return 30;
case 7: return 31;
case 8: return 31;
case 9: return 30;
case 10: return 31;
case 11: return 30;
case 12: return 31;
default: return 0;
}
}