Subject Re: [firebird-support] adding one year to date
Author Raigo
thanks, I got this to work.

but I have one more question, about CAST'ing strings back to date. Is
there something like Delphi has EncodeDate in Firebird?

In my machine date format is dd.mm.yyyy, and putting them together in
that order works, but date format can be anything else, then joining
just strings with dots can cause problems?

Raigo



Dimitry Sibiryakov wrote:

> On 28 Apr 2004 at 15:17, Raigo wrote:
>
>
>>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.