SQL Server Hosting – How to Get Day of Week in SQL Server?
|SQL Server 2008 introduced DATENAME function that return name of datepart of the specified date.
Syntax
1 |
DATENAME ( datepart , date ) |
Example
1 2 3 4 5 6 7 |
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
HostForLIFE.eu SQL Server 2016 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.