Good morning,
I am using a calendar form control to grab user selected dates and date ranges. On a calendar click event I refresh my form to show the user the selected start and end dates.
As part of the refresh, I update a text field to show the weekday and the date:
txtStartDate.Text = WeekdayName(Weekday(startDate)) + " " + startDate
However the weekday I am getting is 1 day out (Tuesday shows as Monday, Monday is showing as Sunday, and Sunday is showing as Saturday.)
To get around this I did the following:
txtStartDate.Text = WeekdayName(Weekday(startDate) - 1) + " " + startDate
This worked for Monday - Saturday, but when I select a Sunday on the calendar, it (obvious in hindsight!) crashes as it cannot display a date with value -1!
I have tried in vain to find a way to set the first day of the week as Monday instead of Sunday. I have done this to the calendar control but this only changes the displayed start day, not the value of the day. I have tried changing the CurrentCulture settings:
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-UK")
Thread.CurrentThread.CurrentUICulture = New CultureInfo("en-UK")
This doesn't work either.
How can I set Monday as being day 0 in Weekday(startDate)?