Create Function dbo.GetDaysName
(@day1 Date
,@day2 Date
,@day varchar(10)
)Returns @t TABLE (Name VARCHAR(20))
As
Begin
Declare @i int =0
while @i<=DATEDIFF(DAY,@Day1,@day2)
Begin
if DATENAME(dw,DATEADD(day,@i,@Day1))=@day
Begin
insert into @t Values(DATEADD(day,@i,@Day1))
End
set @i=@i+1
ENd
RETURN
End
/*
Execute Example:
Select name from dbo.GetDaysName('2015-08-31','2015-10-01','Monday')
It will list out only Monday date between these two dates
In the above line you can use any day name .
*/
(@day1 Date
,@day2 Date
,@day varchar(10)
)Returns @t TABLE (Name VARCHAR(20))
As
Begin
Declare @i int =0
while @i<=DATEDIFF(DAY,@Day1,@day2)
Begin
if DATENAME(dw,DATEADD(day,@i,@Day1))=@day
Begin
insert into @t Values(DATEADD(day,@i,@Day1))
End
set @i=@i+1
ENd
RETURN
End
/*
Execute Example:
Select name from dbo.GetDaysName('2015-08-31','2015-10-01','Monday')
It will list out only Monday date between these two dates
In the above line you can use any day name .
*/
No comments:
Post a Comment