Check if dateTime is a weekend or a weekday

You are comparing your ASP.NET label dayToday against an enumeration element of DayOfWeek which of course fails

Probably you want to replace dayToday with day in your if statement, i.e. from

if ((dayToday == DayOfWeek.Saturday) && (dayToday == DayOfWeek.Sunday))

to

if ((day == DayOfWeek.Saturday) && (day == DayOfWeek.Sunday))

In addition, you probably also want to replace the logical 'and' (&&) with a logical 'or' (||) to finally

if ((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday))

You wrote wrong varable in the following if statement:

if ((dayToday == DayOfWeek.Saturday) || (dayToday == DayOfWeek.Sunday))
{
    Console.WriteLine("This is a weekend");
}

instead of dayToday you must use day varable in the condition.

UPDATE: Also you made mistake in condition. There must be or instead of and.

Correct code is

if ((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday))
{
    Console.WriteLine("This is a weekend");
}

Tags:

C#

Datetime