ronaldmacdonald
MIS
Hi
I am trying to work out the number of working days between 2 dates, including public holidays. Working days are classed as Monday - Friday.
The input two dates are date values stored in two separate tables (U3L.DPL.DATE1 and (U3L.DTK.DATE2). I have a query that produces the number of working days (excluding public holidays) as below:
SELECT U3L.DPL.DATE1,U3L.DTK.DATE2,
(U3L.DTK.DATE2-U3L.DPL.DATE1) -2*FLOOR ((U3L.DTK.DATE2-U3L.DPL.DATE1) /7) - DECODE(SIGN(TO_CHAR(U3L.DTK.DATE2,'D')
- TO_CHAR(U3L.DPL.DATE1,'D')),-1,2,0)+DECODE(TO_CHAR(U3L.DPL.DATE1,'D'),7,1,0)-DECODE(TO_CHAR(U3L.DPL.DATE1,'D'),7,1,0) as Workdays
FROM U3L.DTK,U3L.DPL
WHERE U3L.DPL.KL = U3L.DTK.PKL AND U3L.DTK.TASK_CODE = 'VAL' AND U3L.DPL.DATE1 IS NOT NULL
This returns data of the following type:
DATE1 DATE2 WORKDAYS
--------- ---------- ----------
30-MAY-12 31-MAY-12 1
21-MAY-12 25-MAY-12 4
23-MAY-12 29-MAY-12 4
24-MAY-12 29-MAY-12 3
22-MAY-12 29-MAY-12 5
23-MAY-12 29-MAY-12 4
23-MAY-12 30-MAY-12 5
25-MAY-12 25-MAY-12 0
28-MAY-12
25-MAY-12 30-MAY-12 3
28-MAY-12 30-MAY-12 2
28-MAY-12 30-MAY-12 2
12 rows selected.
Now I have public holidays stored in a separate table U3L.DTK.DATE3.
I am struggling to "link" these dates to my query in order to produce a "WORKDAYS" value that counts the "days" between U3L.DPL.DATE1 and U3L.DTK.DATE2 AND makes a deduction for any days found in this range that are listed in U3L.DTK.DATE3
Cheers
Ronald
I am trying to work out the number of working days between 2 dates, including public holidays. Working days are classed as Monday - Friday.
The input two dates are date values stored in two separate tables (U3L.DPL.DATE1 and (U3L.DTK.DATE2). I have a query that produces the number of working days (excluding public holidays) as below:
SELECT U3L.DPL.DATE1,U3L.DTK.DATE2,
(U3L.DTK.DATE2-U3L.DPL.DATE1) -2*FLOOR ((U3L.DTK.DATE2-U3L.DPL.DATE1) /7) - DECODE(SIGN(TO_CHAR(U3L.DTK.DATE2,'D')
- TO_CHAR(U3L.DPL.DATE1,'D')),-1,2,0)+DECODE(TO_CHAR(U3L.DPL.DATE1,'D'),7,1,0)-DECODE(TO_CHAR(U3L.DPL.DATE1,'D'),7,1,0) as Workdays
FROM U3L.DTK,U3L.DPL
WHERE U3L.DPL.KL = U3L.DTK.PKL AND U3L.DTK.TASK_CODE = 'VAL' AND U3L.DPL.DATE1 IS NOT NULL
This returns data of the following type:
DATE1 DATE2 WORKDAYS
--------- ---------- ----------
30-MAY-12 31-MAY-12 1
21-MAY-12 25-MAY-12 4
23-MAY-12 29-MAY-12 4
24-MAY-12 29-MAY-12 3
22-MAY-12 29-MAY-12 5
23-MAY-12 29-MAY-12 4
23-MAY-12 30-MAY-12 5
25-MAY-12 25-MAY-12 0
28-MAY-12
25-MAY-12 30-MAY-12 3
28-MAY-12 30-MAY-12 2
28-MAY-12 30-MAY-12 2
12 rows selected.
Now I have public holidays stored in a separate table U3L.DTK.DATE3.
I am struggling to "link" these dates to my query in order to produce a "WORKDAYS" value that counts the "days" between U3L.DPL.DATE1 and U3L.DTK.DATE2 AND makes a deduction for any days found in this range that are listed in U3L.DTK.DATE3
Cheers
Ronald