Friday, 20 January 2017

Get Name of days between tow dates in sql server



//           Create function


Create FUNCTION [dbo].[Get_NameOf_Days](
@startdate datetime
,@enddate datetime
,@DayValue int -- return the value of days (starting day with sunday- value=1)
,@NameValue int -- return the name of days (starting day with monday- value=0)
)
RETURNS VARCHAR(MAX)
BEGIN
declare @count int =0
    while @startdate<=@enddate
    Begin
        IF DatePart(WEEKDAY,@startdate) = @DayValue
            SET @count=@count+1
        SET @startdate=DateAdd(d,1,@startdate)
    END
RETURN  (select DATENAME(dw,@NameValue)+' : '+CAST(@count as varchar))

END


//           Call  function

select dbo.Get_NameOf_Days('2017-1-1','2017-1-31',1,6)



//           Result


1 comment:

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...