Subject | Re: [firebird-support] Number of months between dates |
---|---|
Author | Raigo |
Post date | 2004-05-12T13:19:58Z |
>Get the FreeUDFLib(by Gregory Deatz) from:thanks. Is it also available for Linux? I understand it was developed for Interbase, will it be compatible in future releases of Firebird?
>http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_udf_libs
>
>It contains a UDF called AgeInMonths. And, I think that is what you
>are looking for.
I tried doing what I need in a stored procedure and think my question can be solved without UDF:
CREATE PROCEDURE SP_PUHKUS (
BEGIN_DATE TIMESTAMP,
END_DATE TIMESTAMP
) RETURNS (
WORKED_MONTHS INTEGER
) AS
declare variable ADay Integer;
declare variable AMonth Integer;
declare variable AYear Integer;
declare variable LDay Integer;
declare variable LMonth Integer;
declare variable LYear Integer;
declare variable years Integer;
declare variable months Integer;
BEGIN
ADay = EXTRACT(DAY from begin_date);
AMonth = EXTRACT(MONTH from begin_date);
AYear = EXTRACT(YEAR from begin_date);
LDay = EXTRACT(DAY from end_date);
LMonth = EXTRACT(MONTH from end_date);
LYear = EXTRACT(YEAR from end_date);
years=LYear-AYear;
months=LMonth-AMonth;
worked_months=(years*12)+months;
IF ((AMonth<>LMonth) and (AYear<>LYear)) then
begin
If (ADay>=15) then worked_months=worked_months-1;
If (LDay<15) then worked_months=worked_months-1;
end
SUSPEND;
END
it has some minor problems still ... for example
select * from SP_puhkus (
'2.6.2004', '20.07.2004'
)
returns 1, but should be 2. if someone has ideas to improve it (of finds more bugs) please let me know.
Raigo