To do this, you need to use bitwise logic. if you would say
WeekDays.Tuesday & WeekDays.WorkDays
then logical logic will return 4 (since 4 & 62 = 4).
Essentially, and says that for each bit position, if both are equal to 1, return that number. So you just need to check if it is> 0.
To get Today in your current format, you will need a little math ...
(int)DateTime.Now.DayOfWeek will return the day of the week from 0 (Sunday) to 6 (Saturday).
We need to match them to fit your range. Fortunately, this is easy to do with Math.Pow.
int today = Math.Pow(2,(int)DateTime.Now.DayOfWeek); if (today&WeekDays.WorkDays>0) isWorkDay = true; else isWorkDay = false;
Chris source share