Hi,
I am using Oracle Database version 11.2.1. I would like to calculate the number of working minutes between two dates where the working hours are Monday - Thursday 8.45am to 17:00pm & Fridays 8:45am to 16:30pm
I found the following function useful in a similar post but wanted some help incorporating the above working days and hours into account
CREATE OR REPLACE
FUNCTION get_bus_minutes_between(
p_start_date DATE,
p_end_date DATE
)
RETURN NUMBER
IS
v_return NUMBER;
BEGIN
with t as (
select case level
when 1 then greatest(p_start_date,trunc(p_start_date) + 9 / 24)
else trunc(p_start_date) + level - 15 / 24
end start_dt,
case connect_by_isleaf
when 1 then least(p_end_date,trunc(p_end_date) + 18 / 24)
else trunc(p_start_date) + level - 8 / 24
end end_dt
from dual
connect by level <= trunc(p_end_date) - trunc(p_start_date) + 1
)
select sum(greatest(end_dt - start_dt,0)) * 24 * 60 work_minutes
into v_return
from t
where trunc(start_dt) - trunc(start_dt,'iw') < 5; -- exclude weekends
RETURN v_return;
END;
/
Can anyone help?