Menu ▼



Posted By :
avatarmrkraju
Total Views : 315

Check given date is weekend or not in sql

There are multiple ways to check the given date is weekend or not.

Sql function DATENAME returns the given date name as Sunday, Monday, Tuesday, ... We can compare the return value with Saturday and Sunday and can determine the given date is weekend or not.

Sql function DATEPART returns the given date number 1 to 7. Where 1-Sunday, 2-Monday, ... 7-Saturday. If the return value is 1 or 7 then the given date is weekend otherwise given date is weekday.

Example

DECLARE @dt DATETIME

SET @dt = GETDATE()

SELECT @dt

SELECT DATENAME(DW, @dt) -- Returns Datename as Sunday, Monday, Tuesday ....

SELECT DATEPART(DW, @dt)  -- Returns Date in number 1-Sunday, 2-Monday, ... 7-Saturday






comments powered by Disqus


Search dotnetlearners.com