Subject Re: [ib-support] CAST
Author Claudio Valderrama C.
""Burak OZLER"" <burak.ozler@...> wrote in message
news:004201c19788$d13b85d0$2464a8c0@......
> Hi all
>
> I want to cast a date variable to char or varchar.
> TARIHSTR = CAST (TARIH AS CHARACTER);
>
> TARIHSTR is char(12)
>
> but I'm having a error:

Of course you have an error, just look at your corrected cast!
tarihstr = cast(tarih as char(12));

If you are using dialect 1, date is really timestamp. In this case and to
assure that in the future you won't get errors if you switch to dialect 3,
you should either
- trap the whole timestamp in char or varchar(24)
- cast the timestamp to date, then to char/varchar(12) or 10 seems enough in
dialect 3.
- additionally, in dialect 3 you get only the first characters of a date by
casting it to a smaller string. If you want to downgrade a timestamp to
date, cast it to date first, then to char(10). If you want to get the day,
since
cast(date_or_timestamp_field as char(2)) won't work in dialect 3, use
extract() instead. So, in dialect 1 and IB5 and IB4, the construction
s = cast(f as char(2));
if (s like '_-')
then s = cast(f as char);
day = s;
is now simply
day = extract(day from f);
and it will work with any dialect.

Inside the engine,
date is a signed long, time is an unsigned long and timestamp is a quad
(isc_timestamp and isc_quad have the same definition, that's a signed long
plus an unsigned long inside a struct). In the API, there are decode and
encode functions to go back and forth between the internal representation
and the time struct used by ANSI C.

C.
--
Claudio Valderrama C. - http://www.cvalde.com - http://www.firebirdSql.org
Independent developer
Owner of the Interbase® WebRing