add

About Me

My photo
Oracle Apps - Techno Functional consultant

Friday, August 5

Calculating Weekdays between two dates

CREATE OR REPLACE FUNCTION totworkdays (fromdate DATE, todate DATE)
RETURN NUMBER
IS
totalsundays NUMBER;
totalsaturdays NUMBER;
BEGIN
totalsundays :=
NEXT_DAY (todate - 7, 'sunday') - NEXT_DAY (fromdate - 1, 'sunday');
totalsaturdays :=
NEXT_DAY (todate - 7, 'saturday') - NEXT_DAY (fromdate - 1, 'saturday');

RETURN (todate - fromdate - (totalsundays + totalsaturdays) / 7 - 1);
END totworkdays;

CALL this function as follows:


declare
lv_tot_work_days number;
BEGIN
lv_tot_work_days := totworkdays ('01-jan-2009', '31-jan-2009');
DBMS_OUTPUT.put_line ('Total Work Days: ' || lv_tot_work_days);
END;

No comments: