sqldatepart

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.


Solution

  • Try:

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