UFN_VOLUNTEER_DAYOFWEEKMATCHES

Returns the true if the given date matches the supplied day of week code.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@DAYOFWEEKCODE tinyint IN
@DATETIME datetime IN

Definition

Copy


            create function dbo.UFN_VOLUNTEER_DAYOFWEEKMATCHES(@DAYOFWEEKCODE tinyint, @DATETIME datetime) returns bit with execute as caller
            as
            begin
                declare @DATEDAYOFWEEK tinyint;

                if @DAYOFWEEKCODE = 0 --everyday

                    return 1;

                set @DATEDAYOFWEEK = datepart(dw,@DATETIME);

                if (@DAYOFWEEKCODE >= 1 and @DAYOFWEEKCODE <= 7) --actual day

                    if (@DATEDAYOFWEEK = @DAYOFWEEKCODE)
                        return 1;
                    else 
                        return 0;

                if @DAYOFWEEKCODE = 8 -- weekends

                    if (@DATEDAYOFWEEK = 1 or @DATEDAYOFWEEK = 7)
                        return 1;
                    else 
                        return 0;

                if @DAYOFWEEKCODE = 9 -- weekdays

                    if (@DATEDAYOFWEEK >= 2 and @DATEDAYOFWEEK <= 6)
                        return 1;
                    else 
                        return 0;
                return 0;
            end