Many a times we come across a scenario where we may need to get Day/Weekday name from Date in Sql Server. In this article we will see how we can get Day/Weekday name from Date in Sql Server.
Approach 1: Using DATENAME Function
We can use DATENAME() function to get Day/Weekday name from Date in Sql Server, here we need specify datepart parameter of the DATENAME function as weekday or dw both will return the same result.
SELECT GETDATE() 'Today', DATENAME(weekday,GETDATE()) 'Day Name' SELECT GetDate() 'Today', DATENAME(dw,GETDATE()) 'Day Name'
RESULT:
Approach 2: Using FORMAT Function
We can aswell use FORMAT function which is introduced in Sql Server 2012 to get Day/Weekday name from Date in Sql Server. It is not an Sql Server native function instead it is .NET CLR dependent function. I would prefer the first approach instead of this approach for getting Day/Weekday name from Date in Sql Server. But FORMAT function provides lot of options compared to DATENAME function. To know more about FORMAT function you may like to go through a detailed article on FORMAT STRING FUNCTION IN SQL SERVER 2012 which I have written couple of years back.
SELECT GETDATE() 'Today', FORMAT(GETDATE(),'dddd') 'Day Name'
1 thought on “How to get Day or Weekday name from date in Sql Server”