I was wondering on how to write a method that will return me a string which will contain the short day name, example:
public static string GetShortDayName(DayOfWeek day)
now if i call:
string monday = GetShortDayName(DayOfWeek.Monday);
I will get back "mo" if culture is en, or "lu" if culture is at example it.
You can extract the day name from a date using the DATENAME() function. The first parameter is the interval (e.g. year, month, day, etc.) and the second is the date itself. To extract the day name, the interval must have one of the following values: weekday, dw , or w .
Option 2: Monday as the First Day of the WeekSELECT DATEADD(week, DATEDIFF(week, 0, RegistrationDate - 1), 0) AS Monday; In the expression above, we add the specified number of weeks to the 0 date.
The DATENAME() function returns a specified part of a date. This function returns the result as a string value.
You can use DateTimeFormatInfo.AbbreviatedDayNames
. For example:
string[] names = culture.DateTimeFormat.AbbreviatedDayNames; string monday = names[(int) DayOfWeek.Monday];
You can use "ddd" in in a custom format string to get the short day name. For example.
DateTime.Now.ToString("ddd");
As suggestby @Loudenvier in comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With