How do I exclude Weekend days in a SQL Server query? How do I exclude Weekend days in a SQL Server query? sql-server sql-server

How do I exclude Weekend days in a SQL Server query?


When dealing with day-of-week calculations, it's important to take account of the current DATEFIRST settings. This query will always correctly exclude weekend days, using @@DATEFIRST to account for any possible setting for the first day of the week.

SELECT *FROM your_tableWHERE ((DATEPART(dw, date_created) + @@DATEFIRST) % 7) NOT IN (0, 1)


SELECT date_createdFROM your_tableWHERE DATENAME(dw, date_created) NOT IN ('Saturday', 'Sunday')


Assuming you're using SQL Server, use DATEPART with dw:

SELECT date_createdFROM your_tableWHERE DATEPART(dw, date_created) NOT IN (1, 7);

EDIT: I should point out that the actual numeric value returned by DATEPART(dw) is determined by the value set by using SET DATEFIRST:
http://msdn.microsoft.com/en-us/library/ms181598.aspx