jr7138
jr7138

Reputation: 49

How do I exclude Weekend days and get start date and end date

Need help with a Start Date and End Date, that will NOT include Saturday and Sunday.

For example, if I run my query on Monday, my start date and end date will be:

1 = July 20th 2 = July 21st

weekdays

I'm tried this, in my Where clause, and get results. But not from Start Date and End Date range that I need:

((DATEPART(dw, [date_field]) + @@DATEFIRST) % 7) NOT IN (0, 1)

But, having issues with coding the StartDT (1) and EndDT (2) as shown on my screen shot.

Upvotes: 0

Views: 227

Answers (1)

Jon
Jon

Reputation: 6046

Try:

WHERE [date_field] BETWEEN [start_date] AND [end_date]
AND DATEPART(dw, [date_field]) NOT IN (6, 7)

Upvotes: 1

Related Questions