I am using the below code to pick the difference between two dates excluding weekends. However, the below method is not accurate. It gives issues when the difference between the two days are very less, e.g. 2 and it includes Saturday OR Sunday.
DAYS= Round((END_TIME-START_TIME)-2*FLOOR((END_TIME-START_TIME)/7)-DECODE(SIGN(TO_CHAR(END_TIME,'D')-
TO_CHAR(START_TIME,'D')),-1,2,0)+DECODE(TO_CHAR(START_TIME,'D'),7,1,0)-
DECODE(TO_CHAR(END_TIME,'D'),7,1,0),0)
Please help