Created
October 10, 2017 21:34
-
-
Save sachintha81/7a452c2d1ef5aebeacdb1aca69b414cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void CalculateAge(DateTime dt1, DateTime dt2, out int years, out int months, out int days) | |
{ | |
DateTime start = dt1 < dt2 ? dt1 : dt2; | |
DateTime end = dt2 > dt1 ? dt2 : dt1; | |
years = 0; | |
months = 0; | |
days = 0; | |
while (start.AddYears(1) < end) | |
{ | |
start = start.AddYears(1); | |
years++; | |
} | |
while (start.AddMonths(1) < end) | |
{ | |
start = start.AddMonths(1); | |
months++; | |
} | |
while (start.AddDays(1) < end) | |
{ | |
start = start.AddDays(1); | |
days++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment