How To Get Day Of Week In SQL Server?

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
How to get day of week in SQL Server

Reference

  • About DATENAME function at MSDN.


Leave your thoughts...

This site uses Akismet to reduce spam. Learn how your comment data is processed.