Sometimes we need to get the day of week in name or number. SQL Server has a couple of inbuilt functions to get the day of week from the given date. To get the name of the day of week, you can use DATENAME function and to get the number of the day of week, you can use DATEPART function.
Example
To get the name of the day of week
Using DATENAME function:
SELECT DATENAME(WEEKDAY, GETDATE())
/* Result */
Wednesday
To get the number of the day of week
Using DATEPART function:
SELECT DATEPART(WEEKDAY, GETDATE())
/* Result */
4
Reference
- About DATENAME function at MSDN.