Subject Re[2]: [firebird-support] How to count leap days from date range.
Author Roland Turcan
Hello all,

I hurrying to get an solution, but what I sent doesn't work in all
cases. I will improve it and send it again.

TRoland;

<<< 11.2.2009 21:33 - Roland Turcan "konf@..." >>>
RT> Hello all,

RT> At the end I will answer myself.

RT> I have forgotten to write next condition, which tells, that function
RT> doesn't return leap day when difference between days is less that one
RT> year.

RT> I wrote next procedure which follows my rules. I am sorry for Slovak
RT> names.

RT> CREATE PROCEDURE POCET_PRESTUPNYCH_DNI (
RT> DATUM_OD Date,
RT> DATUM_DO Date )
RT> RETURNS (
RT> POCET Integer )
RT> AS
RT> DECLARE VARIABLE ROKOV INTEGER;
RT> BEGIN

RT> SELECT datediff (year from :DATUM_OD to :DATUM_DO + 1)
RT> from rdb$database
RT> into :ROKOV;

RT> IF (ROKOV > 0) THEN begin
RT> select datediff (day from :DATUM_OD to :DATUM_DO + 1) - :ROKOV * 365
RT> from rdb$database
RT> into :POCET;
RT> end else begin
RT> POCET = 0;
RT> END

RT> SUSPEND;
RT> END

RT> Anyway, thanks at least for reading and thinking about my mails.

RT> TRoland;

RT> <<< 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