Gets the months between.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cmoss.Util
{
public class DateFunctions
{
/// <summary>
/// Gets the months between.
/// </summary>
/// <param name="first">The first.</param>
/// <param name="last">The last.</param>
/// <param name="inclusive">if set to <c>true</c> [inclusive].</param>
/// <returns></returns>
public static int GetMonthsBetween(DateTime first, DateTime last, bool inclusive)
{
int result = GetDaysBetween(first, last, true) / 30;
return inclusive ? result + 1 : result;
}
/// <summary>
/// Gets the days between.
/// </summary>
/// <param name="first">The first.</param>
/// <param name="last">The last.</param>
/// <param name="inclusive">if set to <c>true</c> [inclusive].</param>
/// <returns></returns>
public static int GetDaysBetween(DateTime first, DateTime last, bool inclusive)
{
TimeSpan span = last - first;
return inclusive ? span.Days + 1 : span.Days;
}
}
}
Related examples in the same category