We don't work on Sundays
-
strText2 = WeekdayName(myCurrentDate.DayOfWeek, False, Microsoft.VisualBasic.FirstDayOfWeek.Monday)
I just found and fixed this in a half-dozen places whilst reviewing event logs for an Azure web app. TBF, this web app is for a strictly M-F organization, so there should be no activity at all on a Sunday...but it does seem to be happening from time to time. btw, yes the datetime variable is a utc tz and dst adjusted datetime for the client. This code was basically just for display. I'm sure there are better ways to do it, but i'm not asking. :)
"Go forth into the source" - Neal Morse
-
strText2 = WeekdayName(myCurrentDate.DayOfWeek, False, Microsoft.VisualBasic.FirstDayOfWeek.Monday)
I just found and fixed this in a half-dozen places whilst reviewing event logs for an Azure web app. TBF, this web app is for a strictly M-F organization, so there should be no activity at all on a Sunday...but it does seem to be happening from time to time. btw, yes the datetime variable is a utc tz and dst adjusted datetime for the client. This code was basically just for display. I'm sure there are better ways to do it, but i'm not asking. :)
"Go forth into the source" - Neal Morse
Quote:
VisualBasic.FirstDayOfWeek.Monday
That's the International Standard. I don't understand what the problem was.
-
Quote:
VisualBasic.FirstDayOfWeek.Monday
That's the International Standard. I don't understand what the problem was.
The problem happens when the myCurrentDate variable represents a Sunday where myCurrentDate.DayOfWeek returns a 0. The WeekdayName function expects the first parameter to be between 1 and 7...0 throws an exception. The corrected code is:
rText2 = WeekdayName(myCurrentDate.DayOfWeek + 1, False, Microsoft.VisualBasic.FirstDayOfWeek.Sunday)
"Go forth into the source" - Neal Morse
-
The problem happens when the myCurrentDate variable represents a Sunday where myCurrentDate.DayOfWeek returns a 0. The WeekdayName function expects the first parameter to be between 1 and 7...0 throws an exception. The corrected code is:
rText2 = WeekdayName(myCurrentDate.DayOfWeek + 1, False, Microsoft.VisualBasic.FirstDayOfWeek.Sunday)
"Go forth into the source" - Neal Morse
No, the real corrected code is:
rText2 = myCurrentDate.ToString("dddd")
Custom Date and Time Format Strings | Microsoft Docs[^] Or, if you really want to pad the code out:
rText2 = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetDayName(myCurrentDate.DayOfWeek)
The vast majority of the
Microsoft.VisualBasic
assembly is just there for backwards-compatibility with VB6, and should be avoided wherever possible. :)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
No, the real corrected code is:
rText2 = myCurrentDate.ToString("dddd")
Custom Date and Time Format Strings | Microsoft Docs[^] Or, if you really want to pad the code out:
rText2 = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetDayName(myCurrentDate.DayOfWeek)
The vast majority of the
Microsoft.VisualBasic
assembly is just there for backwards-compatibility with VB6, and should be avoided wherever possible. :)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer