How to find the Date is first day of the Week in SQL.

Some time you asked to find the given date is first day of the week or not?
here is the code.

IF DATEPART(DW,GETDATE()) = @@DATEFIRST
BEGIN
    PRINT CONVERT(VARCHAR,GETDATE(),110) + ' IS FIRST DAY OF THE WEEK'
END
ELSE
BEGIN
    PRINT CONVERT(VARCHAR,GETDATE(),110) + ' IS NOT A FIRST DAY OF THE WEEK'
END

0 comments:

Post a Comment