Search code examples
c#asp.netdatetimedayofweek

Get first three characters from DayOfWeek , Month


I've a datetime:

DateTime dt = new DateTime(2003, 5, 1);
dt.DayOfWeek // returns Thursday

How I can split only first three characters from DayOfWeek e.g. Thu?


Solution

  • If you mean for it to work in different cultures, then your best bet is probably:

    var abbr = culture.DateTimeFormat.GetAbbreviatedDayName(dayOfWeek);
    

    where culture is a CultureInfo, for example:

    var culture = CultureInfo.CurrentCulture;
    

    In English cultures, this is the 3-letter version:

    Sun
    Mon
    Tue
    Wed
    Thu
    Fri
    Sat