Skip navigation.

Connecticut Code Camp Follow-upAll recent postsRandom Thoughts

How to Display Day Names In The Right Order

What happens when you call AbbreviatedDayNames is you get an array of day names in the language of the current culture. There’s a caveat: the array always starts with a Sunday even if the first day in that particular culture is Monday. This disconnect can be very confusing if you’re plotting day names against a chart axis, for example.

To list day names in the right order, you have to rely on the FirstDayOfWeek property. Basically, you need to rearrange day names based on what the first day of the week actually is.

Below is a snippet that does exactly that (derived from the Calendar control source):

DateTimeFormatInfo dtfi = CultureInfo.CurrentUICulture.DateTimeFormat;

List<string> dayNames = new List<string>(7);
int firstDayIndex = (int) dtfi.FirstDayOfWeek;

for (int i = firstDayIndex; i < (firstDayIndex + 7); i++)
{
    int adjustedIndex = i % 7;
    
    string dayName = 
           dtfi.GetAbbreviatedDayName ((DayOfWeek) adjustedIndex);

    dayNames.Add (dayName);
}

Below are results for the en-US (English / United States) and de-AT (Deutsch/Österreich) cultures respectively:

[ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
[ "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So" ]

Comments

No comments yet

Emails and Notifications

Would you like to be notified when somebody responds to this post? 

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):