Convert days to weeks and months c# code example

Example 1: total months between two dates c#

((date1.Year - date2.Year) * 12) + date1.Month - date2.Month

Example 2: convert number of days into months c#

//This function is meant for general conversions only.  
//Converting the months between two known date ranges may cause odd results
private int ConvertDaysToMonths(double days)
{
  // Divide by this constant to convert days to months.
  const double daysToMonths = 30.4368499;

  return Convert.ToInt32(Math.Floor(days / daysToMonths));
}