DateTime StartDate = Convert.ToDateTime("01/1/2010");DateTime EndDate = Convert.ToDateTime("02/15/2010");string strResult = ConvertDaysToMonths(StartDate, EndDate);
public string ConvertDaysToMonths(DateTime StartDate, DateTime EndDate) { DateTime oldDate; DateTime.TryParse(StartDate.ToShortDateString(), out oldDate); DateTime currentDate = EndDate; TimeSpan difference = currentDate.Subtract(oldDate); // This is to convert the timespan to datetime object DateTime DateTimeDifferene = DateTime.MinValue + difference; // Min value is 01/01/0001 // subtract our addition or 1 on all components to get the actual date. int InYears = DateTimeDifferene.Year - 1; int InMonths = DateTimeDifferene.Month - 1; int InDays = DateTimeDifferene.Day - 1; return ((InYears * 12) + InMonths).ToString() + " Months " + InDays.ToString() + " Days"; }