Function Controlling Weekdays in SQL Server

Hello everyone,

In this article, I will give information about the function that controls weekdays in SQL Server.

In SQL Server we may want to check the weekdays in some cases.

You can easily do this with the help of the function below.

CREATE FUNCTION CheckYourWeekdays
(
    @Date DATE
)
RETURNS BIT
AS
BEGIN
    DECLARE @Weekdays BIT = 1;
    IF DATENAME(DW, @Date) IN ( 'SATURDAY', 'SUNDAY' )
        SET @Weekdays = 0;
    RETURN @Weekdays;
END; 

---Using the Function

SELECT dbo.CheckYourWeekdays(GETDATE());

When you run the code, you will get a result like the one below.

Function Controlling Weekdays in SQL Server

As you can see, the weekdays were checked.

Good luck to everyone in business and life.

212 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!