SQL – How to get the day of the week
Using the DATEPART function to calculate the integer value of the day of the week.
select datepart(dw,getdate()) as DayOfWeekINT
Output:
DayOfWeekINT
————
2
1 = Sunday
2 = Monday
3 = Tuesday
4 = Wednesday
5 = Thursday
6 = Friday
7 = Saturday
Using the DATENAME function to calculate the day of the week.
select datename(dw,getdate()) as DayOfWeekCHAR
Output:
DayOfWeekCHAR
——————————
Monday
You can get the day of the week for a given date (MM/DD/YYYY) using:
select datepart(dw,’03/07/2011′) as DayOfWeekINT
select datename(dw,’03/07/2011′) as DayOfWeekCHAR
Advertisement
Categories: SQL
date, datename, datepart, day of week, dayofweek, getdate, SQL, sql server