Subject | Re: [firebird-support] adding one year to date |
---|---|
Author | Raigo |
Post date | 2004-04-30T07:52:53Z |
I am now doing like this:
(from http://www.volny.cz/iprenosil/interbase/ip_ib_code_timestamp.htm)
CREATE PROCEDURE Is_LeapYear (Y INTEGER) RETURNS (LY INTEGER) AS
BEGIN
IF ( 60 = EXTRACT(YEARDAY FROM CAST(Y || '-3-1' AS TIMESTAMP)) ) THEN
LY = 1; /* leap year */
ELSE
LY = 0; /* normal year */
END
My procedure:
CREATE PROCEDURE KPV_AASTA (
A TIMESTAMP
) RETURNS (
L TIMESTAMP
) AS
declare variable ADay varchar(2);
declare variable AMonth varchar(2);
declare variable AYear Integer;
BEGIN
ADay = EXTRACT(DAY from A);
AMonth = EXTRACT(MONTH from A);
AYear = EXTRACT(YEAR from A);
AYear=AYear+1;
IF ((Is_LeapYear(AYear)=1) AND (AMonth=2) AND (ADay=29)) THEN ADay=28;
L = CAST(CAST(ADay as VARCHAR(2))||'.'||
CAST(AMonth as VARCHAR(2))||'.'||
CAST(AYear as VARCHAR(4)) as DATE)-1;
suspend;
END
I get error: FUNCTION UNKNOWN IS_LEAPYEAR
what may be wrong?
(from http://www.volny.cz/iprenosil/interbase/ip_ib_code_timestamp.htm)
CREATE PROCEDURE Is_LeapYear (Y INTEGER) RETURNS (LY INTEGER) AS
BEGIN
IF ( 60 = EXTRACT(YEARDAY FROM CAST(Y || '-3-1' AS TIMESTAMP)) ) THEN
LY = 1; /* leap year */
ELSE
LY = 0; /* normal year */
END
My procedure:
CREATE PROCEDURE KPV_AASTA (
A TIMESTAMP
) RETURNS (
L TIMESTAMP
) AS
declare variable ADay varchar(2);
declare variable AMonth varchar(2);
declare variable AYear Integer;
BEGIN
ADay = EXTRACT(DAY from A);
AMonth = EXTRACT(MONTH from A);
AYear = EXTRACT(YEAR from A);
AYear=AYear+1;
IF ((Is_LeapYear(AYear)=1) AND (AMonth=2) AND (ADay=29)) THEN ADay=28;
L = CAST(CAST(ADay as VARCHAR(2))||'.'||
CAST(AMonth as VARCHAR(2))||'.'||
CAST(AYear as VARCHAR(4)) as DATE)-1;
suspend;
END
I get error: FUNCTION UNKNOWN IS_LEAPYEAR
what may be wrong?