Subject Re: extract "date 00:00:00" from timestamp
Author mcbootchek
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
wrote:
> At 03:35 PM 21/02/2005 +0000, you wrote:
> 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
Thanks a lot Helen. As I am not an Admin, it is not easy to swithch to
dialect 3. Anyway I need the date information for SELECT x GROUP BY
only statement (it is not intended to store it in the database). My
SELECT (se foloowing code) looks nearly like yours so it is a great
award to me :)))
Thanks a lot anyway.

SELECT
(CAST ((
(extract (DAY FROM DATE))||'.'||
(extract (MONTH FROM DATE))||'.'||
(extract (YEAR FROM DATE))) AS DATE)) NEW_DATE