title: Datediff excluding weekends
body: <p>I have a query that calculates the turn-around-time, difference in days, between two dates. The dates are in a business process for approval of applications. </p>
  
  <p>Therefore, if the first user approves an application on Friday and the next user approves on Monday, the expected TAT is 1.</p>
  
  <p>I have managed to achieve this result apart from in a rare scenario where both approvals are done on a weekend which returns a TAT of -1 as shown below:</p>
  
  <p><a href="https://i.stack.imgur.com/TYEmA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TYEmA.png" alt="enter image description here"></a></p>
  
  <p>I would like this to return a TAT of 0.</p>
  
  <p>The following is my datediff calculation:</p>
  
  <pre><code>SELECT STEP_ONE, STEP_TWO,
  
  (DATEDIFF(dd, STEP_ONE,STEP_TWO))
    -(DATEDIFF(wk, STEP_ONE,STEP_TWO) * 2)
    -(case datepart(dw, STEP_ONE)+@@datefirst when 8 then 1 else 0 end) 
    -(case datepart(dw, STEP_TWO)+@@datefirst when 7 then 1 when 14 then 1 else 0 end)
    AS TAT 
  
  FROM TEST_1
  </code></pre>