Is there a way to find the days that constitute a weekend or workweek based on different cultures using the .NET framework? For example, some Muslim countries have a workwee
The below code will work till the time last 2 days are considered as weekends in cultures.
:)
///
/// Returns true if the specified date is weekend in given culture
/// is in.
///
public static bool IsItWeekend(DateTime currentDay, CultureInfo cultureInfo)
{
bool isItWeekend = false;
DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;
DayOfWeek currentDayInProvidedDatetime = currentDay.DayOfWeek;
DayOfWeek lastDayOfWeek = firstDay + 4;
if (currentDayInProvidedDatetime == lastDayOfWeek + 1 || currentDayInProvidedDatetime == lastDayOfWeek + 2)
isItWeekend = true;
return isItWeekend;
}