1

Any help with the syntax would be appreciated.

Datediff(day,dateOne, dateTwo) as TimeServed

How would I get the number of days between those dates excluding Saturday and Sunday? I do not have the ability to create functions.

Toby
  • 135
  • 2
  • 17
  • 1
    Possible duplicate of [Calculate diffference between 2 dates in SQL, excluding weekend days](http://stackoverflow.com/questions/8331951/calculate-diffference-between-2-dates-in-sql-excluding-weekend-days) – Andrew Mortimer Dec 15 '15 at 13:48
  • @Mort The possible duplicate was for Oracle and not SQL. – Toby Dec 16 '15 at 19:59
  • http://stackoverflow.com/questions/252519/count-work-days-between-two-dates – Andrew Mortimer Dec 16 '15 at 20:14
  • @Mort Thanks! With that being said, do I close out the question in some regard? If so, how? – Toby Dec 17 '15 at 13:05
  • Normally, if someone had answered the question, you could mark that answer as the accepted answer. Don't think there is anything else you can do with this one though. – Andrew Mortimer Dec 17 '15 at 13:12

1 Answers1

0

Please check out below code, it might help:

declare @firstdate Date
declare @seconddate Date

set @firstDate = convert(date, '2019-11-01')
set @seconddate = convert(date, '2019-11-30')


select ((datediff(dd, @firstDate, @secondDate)+1) - 
    ( DateDiff(wk, @firstDate, @secondDate) * 2) - 
      case when datepart(dw, @FirstDate) = 1 then 1 else 0 end -
      case when datepart(dw, @secondDate) = 7 then 1 else 0 end)
Nilesh Thakkar
  • 2,877
  • 1
  • 24
  • 43