We have need to calculate the number of hours between 2 dates, minus weekends. We’re using the OrderHistory tab’s rows.
I have it working for just the number of days between 2 dates, and then did it for the number of hours (I simply removed TRUNC() around the 2 dates).
But that included weekends and now the team wants just business days. I was able find a solution for 2 dates, but it doesn’t include the hours.
I’m thinking the solution is to add HH24:MM:SS to the to_date() function but am receiving errors.
How do I format to_date() to include hours in the calculation?
SELECT
Site,
OrderNo,
status,
lag_status,
dt,
lag_dt,
TO_CHAR(to_date(dt,'YYYY/MM/DD'),'DY','nls_date_language=english') as DT_DAY,
TO_CHAR(to_date(lag_dt,'YYYY/MM/DD'),'DY','nls_date_language=english') as LAG_DT_DAY,
(to_date(dt,'YYYY/MM/DD') - to_date(lag_dt,'YYYY/MM/DD') ) -
((((TRUNC(to_date(dt,'YYYY/MM/DD'),'D'))-(TRUNC(to_date(lag_dt,'YYYY/MM/DD'),'D')))/7)*2) -
(CASE WHEN TO_CHAR(to_date(lag_dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SUN' THEN 1 ELSE 0 END) -
(CASE WHEN TO_CHAR(to_date(dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SAT' THEN 1 ELSE 0 END) as Bus_Days_Diff
from ifsinfo.RW_OUT_ORDERS_HIST_ONE_LAG