Get day of week in SQL Server 2005/2008

aaaa picture aaaa · Jul 10, 2009 · Viewed 766.9k times · Source

If I have a date 01/01/2009, I want to find out what day it was e.g. Monday, Tuesday, etc...

Is there a built-in function for this in SQL Server 2005/2008? Or do I need to use an auxiliary table?

Answer

SQLMenace picture SQLMenace · Jul 10, 2009

Use DATENAME or DATEPART:

SELECT DATENAME(dw,GETDATE()) -- Friday
SELECT DATEPART(dw,GETDATE()) -- 6