Search code examples
c#date-arithmetic

Finding Date of Birth given age in months


I'm really stuck with calculating date of birth given a persons age in months. Currently, I'm using C# to do that. However, failed to understand the logic. Thanks in advance


Solution

  • DateTime has perfect method to substract (actually add negative value) months from current date. For example:

    int ageInMonths = 18;
    DateTime dt = DateTime.Today;
    DateTime DateOfBirth = dt.AddMonths(-ageInMonths);