DateTime d1 = new DateTime(2002, 1, 1);
DateTime d2 = new DateTime(2000, 10, 1);
int M = Math.Abs((d1.Year - d2.Year));
int months = ((M * 12) + Math.Abs((d1.Month - d2.Month)));
above code first get diffrence between two date.
then it multiply by 12. to get number of months and then at last it getting number of months between two date.