Re: rounding timestamps

From: Joe Conway <mail(at)joeconway(dot)com>
To: Claudio Lapidus <clapidus(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: rounding timestamps
Date: 2003-11-24 03:31:26
Message-ID: 3FC17B8E.809@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Claudio Lapidus wrote:
> test=> select to_char(timestamp '2003-10-24 15:30:59.999',
> 'YYYYMMDDHH24MISS');
> to_char
> ----------------
> 20031024153059
> (1 row)
>
> But my problem is that to_char truncates the fractional seconds, and I need
> to round the value to the nearest integer second. In the above, I would need
> the output rounded to 15:31:00, which is just a millisecond away, for
> example. But I couldn't find a function to round a timestamp. Are there any
> workaround?

Is this what you wanted?

regression=# select to_char(timestamp(0) '2003-10-24
15:30:59.999','YYYYMMDDHH24MISS');
to_char
----------------
20031024153100
(1 row)

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

HTH,

Joe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christopher Browne 2003-11-24 03:48:41 Re: Where is Postgesql ? - MYSQL SURPRISES WITH MAXDB /
Previous Message Alvaro Herrera 2003-11-24 03:27:41 Re: rounding timestamps