DateTime - Between

A T extension method that check if the value is between (exclusif) the minValue and maxValue.

Try it

public static void Main()
{
    DateTime searchDate = DateTime.Now;
	
	DateTime minDate = new DateTime(2018, 12, 25);
	
	DateTime maxDate = new DateTime(2019, 2, 28);

    // C# Extension Method: DateTime - Between
	if(searchDate.Between(minDate, maxDate))
	{
		Console.WriteLine("{0} is between {1} --- {2}", searchDate, minDate, maxDate);
	}
	else
	{
		Console.WriteLine("{0} is not between {1} --- {2}", searchDate, minDate, maxDate);
	}
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     A T extension method that check if the value is between (exclusif) the minValue and maxValue.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="minValue">The minimum value.</param>
    /// <param name="maxValue">The maximum value.</param>
    /// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns>
    /// ###
    /// <typeparam name="T">Generic type parameter.</typeparam>
    public static bool Between(this DateTime @this, DateTime minValue, DateTime maxValue)
    {
        return minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1;
    }
}