Converting DayOfWeek enum to a string repesenting the day

James picture James · Jan 30, 2010 · Viewed 28.2k times · Source

I was wondering if there was a way to directly convert the integer DayOfWeek returns into a string representing the day like Monday, Tuesday etc.

Sample code:

MessageBox.Show(Date.Today.DayOfWeek)

This will return 6 (as of today). Is there a way to directly convert this into Saturday, for example? I don't really care what it really converts it into, but I want to do away with my Select Case:

Select Case Date.Today.DayOfWeek
     Case 0
         day = "Sunday"
     Case 1
         day = "Monday"
     Case 2
         day = "Tuesday"
     Case 3
         day = "Wednesday"
     Case 4
         day = "Thursday"
     Case 5
         day = "Friday"
     Case 6
         day = "Saturday"
     Case Else
         day = "Apocalypse: we're all boned."
 End Select

Thanks :)

Answer

itowlson picture itowlson · Jan 30, 2010

DateTimeFormatInfo.CurrentInfo.GetDayName.