Subject first and last day of a month
Author Sergio H. Gonzalez
Hello, this is another "the best way of doing..." question!

I need a function which returns the fist and last date of a given month of a
year. This is what I did and is working properly, but I'd like to know if there
are better ways of doing it. Im using FB 2.1. Probably there is some UDF ?? By
the way, is there a complete list of UDFs on internet? Thanks! -sergio



CREATE PROCEDURE FIRST_LAST (
par_month integer,
par_year integer)
returns (
out_desde date,
out_hasta date)
as
declare variable loc_str_desde char(10);
begin

/* first day */
loc_Str_Desde = CAST( par_Year as Char(4) ) || '/' ||
CAST( par_Month as Char(2) ) || '/01';


out_Desde = CAST( loc_Str_Desde as DATE );

EXECUTE PROCEDURE
NEXT_MONTH (:par_Month, :par_Year)
RETURNING_VALUES :par_Month, :par_Year;

/* first day of the next month */
loc_Str_Desde = CAST( par_Year as Char(4) ) || '/' ||
CAST( par_Month as Char(2) ) || '/01';

/* less 1 = last day of my month */
out_Hasta = CAST( loc_Str_Desde as DATE ) - 1;

end

-----------------------------------------------------

CREATE PROCEDURE NEXT_MONTH (
par_month integer,
par_year integer)
returns (
out_month integer,
out_year integer)
as
begin

par_Month = par_Month + 1;


if (par_Month > 12) then
begin
par_Month = 1;
par_Year = par_Year + 1;
end

out_Month = par_Month;

out_Year = par_Year;

end