Click here to Skip to main content
Click here to Skip to main content

Rearrange day of week and capitalize day names in .Net

, 1 Jun 2010
Rate this:
Please Sign up or sign in to vote.
Zero-index will return monday (or any other day based on FirstDayOfWeek in culture)
As you might know CultureInfo will return day names from Sunday to Saturday. We in Europe start a week with Monday.
 
So I wrote a tiny function that will return day names in European style, and when you will request DayOfName(0) it will return Monday, instead of Sunday.
 
Also function will return capitalized name of day, in case you are just listing days and don't use them in context (when one should write day name lower case in some languages).
 

Public Function NameOfDay(ByVal dayOfWeek As Integer) As String
    ' Offset because of first day of week
    Dim CurrentDay As Integer = (CurrentCulture.DateTimeFormat.FirstDayOfWeek + dayOfWeek) Mod 7
 

    ' Format name to have first letter uppercase
    Return CurrentCulture.DateTimeFormat.DayNames(CurrentDay).Substring(0, 1).ToUpper & CurrentCulture.DateTimeFormat.DayNames(CurrentDay).Substring(1)
End Function
 

Above function does not rearrange day names inside culture info (which could be done) instead just temporary rearranges it in memory and returnes proper day name starting from Monday (for index 0) and finishing on Sunday (for index 6).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Enver Maroshi

Croatia Croatia
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 2 Jun 2010
Article Copyright 2010 by Enver Maroshi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid