Subject RE: [firebird-support] adding one year to date
Author Alan McDonald
> >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.
>
> In a procedure you can use something like this:
>
> ADay = EXTRACT(DAY from TheDate);
> AMonth = EXTRACT(MONTH from TheDate);
> AYear = EXTRACT(YEAR from TheDate);
> NextYearDate = CAST(CAST(ADay as VARCHAR(2))||'.'||
> CAST(AMonth as VARCHAR(2))||'.'||
> CAST(AYear+1 as VARCHAR(4)) as DATE)-1;
>
> You'll be in troubles with 29.02, but it is a matter of one
> additional check.
>
> You can also just use addYear UDF from fbudf library.
>
> SY, Dimitry Sibiryakov.

Yes - and there is the addMonth function too but unfortunately, adding one
month to a 28 or 30 day month does not result in the last day of the next
month, merely the same date in the next month. So there some work to do
there too.
Alan