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

IsWeekend

Lets you easily figure out ifdateTime holds a date value that is a weekend.

Source

public static bool IsWeekend(this DateTime value)
{
    return (value.DayOfWeek == DayOfWeek.Sunday || value.DayOfWeek == DayOfWeek.Saturday);
}

Example

for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
{
    if (date.IsWeekend()) continue;
    // do some date related stuff
}

Author: DavidV

Submitted on: 10 mrt. 2008

Language: C#

Type: System.DateTime

Views: 12139