SQL Server 2008 introduced DATENAME function that return name of datepart of the specified date.
Syntax
DATENAME ( datepart , date )
Example
- SELECT GETDATE() DAte_, DATENAME(dw,GETDATE()) as DayName_
- UNION ALL
- SELECT DATEADD(DAY,1,GETDATE()) DAte_, DATENAME(dw,GETDATE()+1) as DayName_
- UNION ALL
- SELECT DATEADD(DAY,2,GETDATE()) DAte_, DATENAME(dw,GETDATE()+2) as DayName_
- UNION ALL
- SELECT DATEADD(DAY,3,GETDATE()) DAte_, DATENAME(dw,GETDATE()+3) as DayName_
Output
In this example we use "dw" to get the Day Name but you can use "mm" to get the month name and "yy" to get the year value.
Example