Wednesday, June 22, 2016

Sql server: Get month calendar with week day name

In this article I am going to explain how to get month calendar with week day name in sql server.


Implementation:

To get month calendar with week day name run the below given query in Sql server:


declare @StartDate datetime
declare @Enddate datetime
set @StartDate = '20160601'

set @Enddate ='20160630'
;with dates as(
    select @StartDate as sdt
    union all
    select DATEADD(d,1,sdt) from dates where sdt<@Enddate
)
select ROW_NUMBER() OVER (ORDER BY sdt) AS [serial number], sdt as [Date], datename(dw,sdt)as [Week Day Name] from dates



Result:
Sql server: Get month calendar with week day name

No comments:

Post a Comment