Re: .TO_CHAR problem

From: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
To: Guillaume Lémery <glemery(at)comclick(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: .TO_CHAR problem
Date: 2001-02-19 08:27:31
Message-ID: Pine.LNX.3.96.1010219092323.15975A-100000@ara.zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Thu, 15 Feb 2001, Guillaume [ISO-8859-1] Lémery wrote:

> Hi all,
>
> I want to have some stats from my data grouped by 2hours periodes.
>
> Here is the query :
>
> SELECT TO_DATE(TO_CHAR (date_clic,'DD-MM-YYYY ')
> || (TO_CHAR(
> TO_NUMBER(
> TO_CHAR(date_clic,'hh24')
> , 99)
> - mod(
> TO_NUMBER(
> TO_CHAR(date_clic,'hh24')
> , 99)
> ,2)
> , 'hh24')
> )
> ||':00','DD-MM-YYYY HH24:MI') AS date_debut
> FROM clic_campagne;
>
> But I only get the date whithout the hours and the minute, how can I get
> them ?

As you say "..get the date...", hours+minutes+ contains timestamp.

You must call SELECT TO_TIMESTAMP(...) instead TO_DATE(...).

BTW, I not sure if your TO_NUMBER() is needful, less expensive will
probably TO_CHAR(date_clic,'hh24')::int.

Karel

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2001-02-19 09:25:20 Re: Default values?
Previous Message Mark Cowlishaw 2001-02-19 06:46:14 not using table aliases in where clause slow-down?