Re: rounding timestamps

From: "Claudio Lapidus" <clapidus(at)hotmail(dot)com>
To: "Joe Conway" <mail(at)joeconway(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>, "Alvaro Herrera" <alvherre(at)dcc(dot)uchile(dot)cl>
Subject: Re: rounding timestamps
Date: 2003-11-24 13:44:10
Message-ID: BAY7-DAV4BG3qlSIjSa00002640@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Joe Conway wrote:
> Is this what you wanted?
>
> regression=# select to_char(timestamp(0) '2003-10-24
> 15:30:59.999','YYYYMMDDHH24MISS');
> to_char
> ----------------
> 20031024153100
> (1 row)

Yes! Exactly!

>
> See:
> http://www.postgresql.org/docs/current/static/datatype-datetime.html

Shame on me. I've must read that page more times than I can remember. I
never realized that I could use the precision qualifier to do a cast (and
round):

comp_20031117=> create table ts (ts timestamp without time zone);
CREATE TABLE
comp_20031117=> insert into ts values ('2003-10-24 15:30:59.999');
INSERT 406299 1
comp_20031117=> select * from ts;
ts
-------------------------
2003-10-24 15:30:59.999
(1 row)

comp_20031117=> select to_char (ts ::timestamp(0), 'YYYYMMDDHH24MISS') from
ts;
to_char
----------------
20031024153100
(1 row)

thank you very much Joe
cl.

PS. Alvaro, your solution was what I was implementing already, but yes it's
ugly, that's why I gave it a second round. Thanks anyway.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff 2003-11-24 14:28:26 Re: Lock strategies!
Previous Message Tom Lane 2003-11-24 13:33:56 Re: why ORDER BY works wrong in pg7.3.4?