SQL Server Date Formats - ddd

How to get the day of the week (in ddd format, so that Mon, Tue, etc.) in SQL? I don't see anything in the CAST and CONVERT documentation.

+4
source share
6 answers

Many ways to do this, here is one way:

SELECT LEFT(DATENAME(dw, GETDATE()), 3) 
+12
source

You can use the DATENAME method to extract the day, and then use SUBSTRING to accept only the first 3 characters.

 SELECT SUBSTRING(DATENAME(DW, '09/11/2009'), 1, 3) 
+3
source

I would use SELECT CONVERT(CHAR(3),DATENAME(weekday,GETDATE()))
to avoid using another function in SQL, conversion to CHAR (3) implicitly takes the first 3 characters.

Jonathan

+3
source

try it

 SELECT DATEPART(DW, '1/1/2009') 

Read DATEPART here

http://msdn.microsoft.com/en-us/library/ms174420.aspx

+1
source

You can’t get him out of the box, but you can do it all day.

eg.

select datename(weekday,getdate())

returns "monday" and you can just take the first 3 letters.

+1
source

For SQL Server 2012 +:

 SELECT FORMAT(GETUTCDATE(),'ddd') AS ShortDayName 

This is much cleaner than subscript. The FORMAT() function can also be passed to the culture for language compatible formatting.

Note that this works for other parts of the date, such as the month:

 SELECT FORMAT(GETUTCDATE(),'MMM') AS ShortMonthName 

FORMAT () Link

+1
source

All Articles