Ismail Gunes
Ismail Gunes

Reputation: 558

How to get from an integer day value day as string

I stored into my database as integer day values. From a string array I was getting the day as string.

public static string[] _dayofweek = new string[] {"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"}; 

However, now I want to get the name of day relatively to cultureinfo not only as fixed in english.

Is it possible to get the names of week from this stored day number ?

Upvotes: 0

Views: 445

Answers (1)

Guvante
Guvante

Reputation: 19203

The easiest way is to use ToString("dddd") on a DateTime. I would pick an arbitrary Sunday and use AddDays to translate your index.

int _dayOfWeek = 1; //Monday
string weekdayString = new DateTime(2015, 4, 12).AddDays(_dayOfWeek)
                                                .ToString("dddd");
                     // ^ "Monday" or whatever locale you are in

Upvotes: 3

Related Questions