DateTimeFormatInfo string format for day of week. Thursday becomes Th

Tony_Henrich picture Tony_Henrich · Jun 16, 2010 · Viewed 31.5k times · Source

Is there a DateTimeFormatInfo format pattern to convert a day of week to two characters? For example Tuesday becomes Tu, Wednesday becomes We. The format string needs to conform to the DateTimeFormatInfo for date formats.

Addition:

Maybe I am looking for a solution to extend DateTimeFormatInfo to include custom formats?

Answer

Oded picture Oded · Jun 16, 2010

The closes you can get is the "ddd" custom format specifier - this produces three lettered abbreviations, so not exactly what you want. There is nothing built in that does exactly what you want.

You can always take the first two characters of that:

DateTime.Now.ToString("ddd").Substring(0,2);

Unfortunately you can't extend DateTimeFormatInfo since it is declared as sealed.