This is a basic logic problem, which is easy to work out if you simply write it out.
From the example you have given, I assume you are working from month start to month end. I.e. Jan 2013 to Jan 2013 would be 1 month; Jan 2012 to Dec 2012 would be 1 year; Jan 2012 to Jan 2013 would be 1 year 1 month.
(Note that for this code it doesn't matter if your months are 1-based or 0-based).
int years = toYear - fromYear;
int months = toMonth - fromMonth + 1;
if (months < 0)
{
--years;
months += 12;
}
After that you need to work out how you want to display this based on "years" and "months". A very simple example (note I've not used any globalization here, etc, and you would probably want to do things like check for the singular "year" and "month", etc.):
if (years > 0)
{
if (months > 0)
{
display = string.Format("{0} years {1} months", years, months);
}
else
{
display = string.Format("{0} years", years);
}
}
else
{
display = string.Format("{1} months", months);
}
Regards,
Ian.