Check if date is a Weekend.

Posted by Vishalneeraj-24503 under Visual Studio category on | Points: 40 | Views : 1361
As,we know that Saturday and Sunday is considered as a weekend,so we can check by using Datetime.DayOfWeek property and DayOfWeek enum value as:-
public static bool IsWeekend(DateTime GivenDate)
// Initialize to true; Means all days are work days.
bool Weekend = false;

// return non work day if saturday or sunday
if (GivenDate.DayOfWeek == DayOfWeek.Saturday || GivenDate.DayOfWeek == DayOfWeek.Sunday)
Weekend = true;
return Weekend;

Comments or Responses

Posted by: Hardcoder on: 4/5/2015 Level:Starter | Status: [Member] | Points: 10
Nice code snippet for getting the weekend.

Login to post response