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
?
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
?
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
Marcs approach is the best here. But if i understand your question in a more general way, how to get the first three letters of an enum
-value, you can use string methods if you use enum.ToString
:
DateTime dt = new DateTime(2003, 5, 1);
string dow = dt.DayOfWeek.ToString();
dow = dow.Length > 3 ? dow.Remove(3) : dow;