ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

IsInRange

Determines if a date is within a given date range

Source

public static bool IsInRange(this DateTime currentDate, DateTime beginDate, DateTime endDate)
{
    return ( currentDate >= beginDate && currentDate <= endDate );
}

Example

var monday = DateTime.Now.ThisWeekMonday();
var friday = DateTime.Now.ThisWeekFriday();

If (DateTime.Now.IsInRange(monday, friday) {
    ...do something...
}

Author: Charles Cherry

Submitted on: 3 mrt 2011

Language: C#

Type: System.DateTime

Views: 7600