How do I loop the whole week (monday-sunday) based on culture info, so in my case monday will be the first day of the week? And is it possible to find the int
value of the day at the same time?
For some information: I need to make this in order to make some generel opening hours for a store.
I think what you need is the following loop.
DayOfWeek firstDay = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
for (int dayIndex = 0; dayIndex < 7; dayIndex++)
{
var currentDay = (DayOfWeek) (((int) firstDay + dayIndex) % 7);
// Output the day
Console.WriteLine(dayIndex + " " + currentDay);
}
The modulo 7 is important, because the firstdayofweek can vary by different cultures.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With