Subject | adding one year to date |
---|---|
Author | Raigo |
Post date | 2004-04-28T12:17:03Z |
How to add exactly one year-1 day to date in Firebird procedure or query? I have to calculate a year period from certain date, for example: 01.05.2002 -> 30.04.2003.
when I do simply: date+364 it works well in most cases, but there is a problem with leap years.
I found a function from internet to check for leap year:
CREATE PROCEDURE IS_LEAPYEAR (
D TIMESTAMP
) RETURNS (
LY INTEGER
) AS
BEGIN
IF ( 2 = EXTRACT(MONTH FROM (D - EXTRACT(YEARDAY FROM D) + 59)) ) THEN
LY = 1; /* leap year */
ELSE
LY = 0; /* normal year */
END
but when I try:
SELECT * FROM IS_LEAPYEAR('27.04.2003');
returned is 'null'.
any ideas?
when I do simply: date+364 it works well in most cases, but there is a problem with leap years.
I found a function from internet to check for leap year:
CREATE PROCEDURE IS_LEAPYEAR (
D TIMESTAMP
) RETURNS (
LY INTEGER
) AS
BEGIN
IF ( 2 = EXTRACT(MONTH FROM (D - EXTRACT(YEARDAY FROM D) + 59)) ) THEN
LY = 1; /* leap year */
ELSE
LY = 0; /* normal year */
END
but when I try:
SELECT * FROM IS_LEAPYEAR('27.04.2003');
returned is 'null'.
any ideas?