Subject Re: [firebird-support] datetime trunc
Author Mark Rotteveel
On 11-2-2014 21:54, Alan McDonald wrote:
> Cast the result of the extract as a date or timestamp.

That doesn't work and that is ok: I'd be surprised when casting the
result (= 20) of EXTRACT(hour from TIMESTAMP '2001-02-16 20:38:40')
would result in 2001-02-16 20:00:00, while the result (= 2001) of
EXTRACT(year FROM TIMESTAMP '2001-02-16 20:38:40') would result in
2001-01-01 00:00:00.

The TS asked for an equivalent function, there is none in Firebird,
although there is a workaround as demonstrated by Ismael.

>
> On 12/02/2014 6:20 AM, "Mark Rotteveel" <mark@...
> <mailto:mark@...>> wrote:
>
> On 11-2-2014 16:06, Virna Constantin wrote:
> >
> >
> > EXTRACT()
> > http://www.firebirdsql.org/refdocs/langrefupd25-intfunc-extract.html
>
> Extract is not the same as PostgreSQL date_trunc. Extract returns the
> requested value as an integer, while date_trunc returns a DATE or
> TIMESTAMP truncated to the requested date field, example from
> http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
> :
>
> SELECT date_trunc('hour', TIMESTAMP '2001-02-16 20:38:40');
> Result: 2001-02-16 20:00:00
>
> SELECT date_trunc('year', TIMESTAMP '2001-02-16 20:38:40');
> Result: 2001-01-01 00:00:00

--
Mark Rotteveel