Between

public static bool Between<T>(this T value, T from, T to) where T : IComparable<T>
        {
            return value.CompareTo(from) >= 0 && value.CompareTo(to) <= 0;
        }
Example:
DateTime today = DateTime.Now;
var from = new DateTime(2012, 2, 1);
var to = new DateTime(2012, 12,20);

bool isBetween = today.Between(from, to);

Description

c# version of "Between" clause of sql query

Details

Double click on the code to select all.

 

;