Subject Re: [firebird-support] Re: extract "date 00:00:00" from timestamp
Author Helen Borrie
At 03:35 PM 21/02/2005 +0000, you wrote:


> > > I mean timestamp stored in the database is something like:
> > > 21.12.2004 08:45:56
> >
> > Isn't
> >
> > select cast(timestampfield as date) from...
> >
> > just what you are looking for?
> > But I only tried that with a dialect 3-db, maybe dialect 1 behaves
> > differently...
>
>Sorry, it does not work in the dialect 1 !!!!!!

In dialect 1, there is no "date-only" type. The best way to achieve what
you want is to format the value in your client code.

If you need to retrieve a date-only representation frequently, consider
adding a CHAR(n) column of suitable size in your table, and writing
triggers to populate it BEFORE UPDATE and BEFORE INSERT; or define it as a
COMPUTED BY field.

The expression you want will be something like the following for a CHAR(10):

CAST(EXTRACT(DAY FROM mydate) as CHAR(2)) || '.' ||
CAST(EXTRACT(MONTH FROM mydate) as CHAR(2)) || '.' ||
CAST(EXTRACT(YEAR FROM mydate) as CHAR(4))

By this method, a date could look like this: '3.2.2005 '. If this is too
ugly for you, then the trigger method will be preferred, since you can
prettify the string before you store it.

On the other hand, a one-time effort to convert the database to dialect 3
would solve your problem forever....

./heLen