Categories
Sql Server

How to Get The Day of The Week in SQL Server

How to Get The Day of The Week in SQL Server

In this post we will learn How to Get The Day of The Week in SQL Server. Sometime this is very useful. In earlier post we had discussed How to Password Protected Backup In SQL ServerHow To Delete Backup Files Older Than n DaysCreating Resource Pools in SQL ServerResource Governor in SQL Server.

DATEPART function to calculate the integer value of the day of the week:

SELECT DATEPART(DW,GETDATE()) AS DAYOFWEEKINT

1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday

 

DATENAME function to calculate the  day of the week:

SELECT DATENAME(DW,GETDATE()) AS DAYOFWEEKCHAR

Get Day of the week for a given date (MM/DD/YYYY) using:

SELECT DATENAME(DW,'07/29/2014') AS DAYOFWEEKCHAR