Subject | Re: [firebird-support] How to count leap days from date range. |
---|---|
Author | Roland Turcan |
Post date | 2009-02-11T20:33:18Z |
Hello all,
At the end I will answer myself.
I have forgotten to write next condition, which tells, that function
doesn't return leap day when difference between days is less that one
year.
I wrote next procedure which follows my rules. I am sorry for Slovak
names.
CREATE PROCEDURE POCET_PRESTUPNYCH_DNI (
DATUM_OD Date,
DATUM_DO Date )
RETURNS (
POCET Integer )
AS
DECLARE VARIABLE ROKOV INTEGER;
BEGIN
SELECT datediff (year from :DATUM_OD to :DATUM_DO + 1)
from rdb$database
into :ROKOV;
IF (ROKOV > 0) THEN begin
select datediff (day from :DATUM_OD to :DATUM_DO + 1) - :ROKOV * 365
from rdb$database
into :POCET;
end else begin
POCET = 0;
END
SUSPEND;
END
Anyway, thanks at least for reading and thinking about my mails.
TRoland;
<<< 11.2.2009 21:13 - Roland Turcan "konf@..." >>>
RT> Hello firebird-support@yahoogroups.com!
RT> I have two dates and I need to count, that how many times occured
RT> 29.2. between two days.
RT> Why:
RT> I need to calculate year interest, but:
RT> INTEREST_AMOUNT = ISTINA * (DATE_FROM - DATE_TO + 1) * INTEREST / 365 / 100;
RT> ...increases the count of days with leap days which gives wrong
RT> computation.
RT> How could I solve this computation using FireBird 2.1 with dialect 3
RT> in stored procedure, but WITHOUT creating any new UDF funtion.
RT> Thanks for all hints in advance.
--
Best regards, TRoland
http://www.rotursoft.sk
http://exekutor.rotursoft.sk
At the end I will answer myself.
I have forgotten to write next condition, which tells, that function
doesn't return leap day when difference between days is less that one
year.
I wrote next procedure which follows my rules. I am sorry for Slovak
names.
CREATE PROCEDURE POCET_PRESTUPNYCH_DNI (
DATUM_OD Date,
DATUM_DO Date )
RETURNS (
POCET Integer )
AS
DECLARE VARIABLE ROKOV INTEGER;
BEGIN
SELECT datediff (year from :DATUM_OD to :DATUM_DO + 1)
from rdb$database
into :ROKOV;
IF (ROKOV > 0) THEN begin
select datediff (day from :DATUM_OD to :DATUM_DO + 1) - :ROKOV * 365
from rdb$database
into :POCET;
end else begin
POCET = 0;
END
SUSPEND;
END
Anyway, thanks at least for reading and thinking about my mails.
TRoland;
<<< 11.2.2009 21:13 - Roland Turcan "konf@..." >>>
RT> Hello firebird-support@yahoogroups.com!
RT> I have two dates and I need to count, that how many times occured
RT> 29.2. between two days.
RT> Why:
RT> I need to calculate year interest, but:
RT> INTEREST_AMOUNT = ISTINA * (DATE_FROM - DATE_TO + 1) * INTEREST / 365 / 100;
RT> ...increases the count of days with leap days which gives wrong
RT> computation.
RT> How could I solve this computation using FireBird 2.1 with dialect 3
RT> in stored procedure, but WITHOUT creating any new UDF funtion.
RT> Thanks for all hints in advance.
--
Best regards, TRoland
http://www.rotursoft.sk
http://exekutor.rotursoft.sk