try using this...

insert your own function for the "business_days_between"

you will also need a "is_business_day" function that returns Y or N.

this is because if you have a start or end day on a weekend you obviously don't want to include those hours. your day counting function will already exlude them, you don't want the hours to put them back in.

the p_start_hour and p_end_hour parameters are used to define the start and end of your business days.

If you start your business day at 6:30am and end at 5:30pm you would pass in

6.5 for p_start_hour and

17.5 for p_end hour

```
FUNCTION business_hours_between(
p_start IN DATE,
p_end IN DATE,
p_start_hour IN NUMBER,
p_end_hour IN NUMBER
)
RETURN NUMBER
IS
v_start DATE;
v_end DATE;
v_count NUMBER := 0;
v_start_time NUMBER;
v_end_time NUMBER;
BEGIN
-- If the parameters are passed in chronologically backwards
-- then reverse them internally and continue.
IF p_start > p_end
THEN
v_start := p_end;
v_end := p_start;
ELSIF p_start < p_end
THEN
v_start := p_start;
v_end := p_end;
ELSE
-- start = end so 0 time
RETURN 0;
END IF;
IF p_start_hour < 0 OR p_start_hour >= p_end_hour OR p_end_hour > 24
THEN
raise_application_error(-20001, 'Invalid business hours');
END IF;
v_start_time := (v_start - TRUNC(v_start)) * 24;
v_end_time := (v_end - TRUNC(v_end)) * 24;
IF TRUNC(v_start) != TRUNC(v_end)
THEN
IF TRUNC(v_end) - TRUNC(v_start) > 1
THEN
-- Business days between is end-point INclusive and ignores time
-- so we only want to count the hours in whole days.
v_count := business_days_between(v_start + 1, v_end - 1) *(p_end_hour - p_start_hour);
END IF;
IF is_business_day(v_start) = 'Y'
THEN
v_count := v_count + GREATEST(0, p_end_hour - GREATEST(v_start_time, p_start_hour));
END IF;
IF is_business_day(v_end) = 'Y'
THEN
v_count := v_count + GREATEST(0, LEAST(v_end_time, p_end_hour) - p_start_hour);
END IF;
ELSE
IF is_business_day(v_end) = 'Y'
THEN
v_count :=
GREATEST(0, LEAST(v_end_time, p_end_hour) - GREATEST(v_start_time, p_start_hour));
END IF;
END IF;
RETURN v_count;
END business_hours_between;
```