Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a short day name

Tags:

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.

like image 739
MaiOM Avatar asked Sep 21 '12 11:09

MaiOM


People also ask

How do I get the day name in SQL?

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 .

How do I get the Monday of the week in SQL?

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.

What is SQL Datename function?

The DATENAME() function returns a specified part of a date. This function returns the result as a string value.


2 Answers

You can use DateTimeFormatInfo.AbbreviatedDayNames. For example:

string[] names = culture.DateTimeFormat.AbbreviatedDayNames; string monday = names[(int) DayOfWeek.Monday]; 
like image 145
Jon Skeet Avatar answered Mar 02 '23 20:03

Jon Skeet


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.

like image 27
mcNux Avatar answered Mar 02 '23 20:03

mcNux