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.
As you can see, the weekdays were checked.
Good luck to everyone in business and life.