Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. We don't work on Sundays

We don't work on Sundays

Scheduled Pinned Locked Moved The Weird and The Wonderful
cloud
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kmoorevs
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • K kmoorevs

      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

      P Online
      P Online
      PIEBALDconsult
      wrote on last edited by
      #2

      Quote:

      VisualBasic.FirstDayOfWeek.Monday

      That's the International Standard. I don't understand what the problem was.

      K 1 Reply Last reply
      0
      • P PIEBALDconsult

        Quote:

        VisualBasic.FirstDayOfWeek.Monday

        That's the International Standard. I don't understand what the problem was.

        K Offline
        K Offline
        kmoorevs
        wrote on last edited by
        #3

        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

        Richard DeemingR 1 Reply Last reply
        0
        • K kmoorevs

          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

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          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

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          K 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            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

            K Offline
            K Offline
            kmoorevs
            wrote on last edited by
            #5

            Thank you Richard! Helpful as always...I knew there had to be a better way! :)

            "Go forth into the source" - Neal Morse

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups