Click here to Skip to main content
12,823,625 members (50,569 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 2 Jun 2010

Rearrange day of week and capitalize day names in .Net

, 2 Jun 2010 CPOL
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).


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

You may also be interested in...

Comments and Discussions

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