Subject | Re: [firebird-support] help on stored procedure for dates |
---|---|
Author | Helen Borrie |
Post date | 2005-03-03T05:43:06Z |
At 03:58 AM 3/03/2005 +0000, you wrote:
commit;
create procedure get_working_days (startdate DATE, enddate DATE)
RETURNS (Number integer)
as
declare incdate date;
begin
if (
(startdate > enddate)
or (startdate is null)
or (enddate is null) ) then
exception INVALID_DATES;
Number = 0;
incdate = startdate;
while (enddate >= incdate) do /* see note 1 */
begin
if (EXTRACT(WEEKDAY FROM incdate) BETWEEN 1 AND 5) then
Number = Number + 1;
incdate = incdate + 1;
end
suspend; /* see note 2 */
end
Notes
1. The actual test depends on whether you want to consider all of the days
in the period (startdate to enddate).
2. Omit if you want to make this an executable procedure and read the
result from the return params.
./hb
>Hellocreate exception INVALID_DATES 'Invalid dates';
>
>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.
commit;
create procedure get_working_days (startdate DATE, enddate DATE)
RETURNS (Number integer)
as
declare incdate date;
begin
if (
(startdate > enddate)
or (startdate is null)
or (enddate is null) ) then
exception INVALID_DATES;
Number = 0;
incdate = startdate;
while (enddate >= incdate) do /* see note 1 */
begin
if (EXTRACT(WEEKDAY FROM incdate) BETWEEN 1 AND 5) then
Number = Number + 1;
incdate = incdate + 1;
end
suspend; /* see note 2 */
end
Notes
1. The actual test depends on whether you want to consider all of the days
in the period (startdate to enddate).
2. Omit if you want to make this an executable procedure and read the
result from the return params.
./hb