Possible Duplicate:
Calculate Years, Months, weeks and Days
How do I calculate difference in years and months given a start and end date?
Hi
Working on a c# 2.0 project and I need to calculate the difference in years and months given the start and end date
I was thinking of a function like
public void CalculateYearsAndMonths(DateTime startDate,
DateTime endDate,
out int years,
out int months)
{
int years=0;
int months=0;
//????
}
any suggestions?
This code works even when number of days between two dates are 365 days. E.g. 29th February 1972 and 28. February 1973, then it will return 0 years and 11 months.
By the way, you need to remove the two lines to make the out parameters work correctly: