Search This Blog

No Of Working Days Till Current Date

CREATE FUNCTION fn_isbusinessday (@date DATETIME)RETURNS INT
AS
BEGIN
DECLARE @return int
DECLARE @CurMonth int
SET @Return = 0
SET @CurMonth = DATEPART(mm,@Date)
SET @Date =DATEADD(DD,-1,@Date)
WHILE DATEPART(mm,@Date) = @curMonth
BEGIN
IF DATENAME(WEEKDAY, @DATE)NOT IN ('saturday', 'sunday')
SELECT @return = @return +1
SET @Date =DATEADD(DD,-1,@Date)
END
RETURN @return
END
GOSELECT dbo.fn_isbusinessday(GETDATE())

No comments: