Subject help on stored procedure for dates
Author donoghue_brendan
Hello

In my developer bag of tricks I have an pl/sql funciton the returns me
the number of days between 2 dates. I am trying to get my head around
how I make this a stored procedure in firebird, but am having
difficulities getting my head around how to do this.

Any help would be greatly appreciated.

Thanks

Brendan Donoghue

CREATE OR REPLACE Function GET_WORKING_DAYS

( P_Start_Date IN Date, P_End_Date IN Date)
RETURN Number IS

-- Declare variables
N_Work_Days Number := 0;
D_Date Date;


BEGIN

D_Date := P_Start_Date;

IF ( P_End_Date > P_Start_Date ) THEN

FOR i IN 1..(P_End_Date - P_Start_Date + 1) LOOP


IF ( (TO_CHAR(D_Date, 'DY') != 'SUN') AND
(TO_CHAR(D_Date,'DY') != 'SAT') ) THEN

N_Work_Days := N_Work_Days + 1;

END IF;

D_Date := D_Date + 1;

END LOOP;


ELSIF P_End_Date = P_Start_Date THEN

N_Work_Days := 0;

ELSE

N_Work_Days := 0;

End if;

-- DBMS_OUTPUT.PUT_LINE('N_Work_Days : ' || TO_CHAR(N_Work_Days));

RETURN N_Work_Days ;

END GET_WORKING_DAYS;
/