Re: Converting seconds past midnight to a time

From: Michael Glaesemann <grzm(at)myrealbox(dot)com>
To: Karl O(dot) Pinc <kop(at)meme(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Converting seconds past midnight to a time
Date: 2005-12-18 04:21:39
Message-ID: 91469550-69FF-48DF-8A9C-0C3012A10371@myrealbox.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-patches


On Dec 18, 2005, at 13:25 , Karl O. Pinc wrote:

> What is the best way to convert an integer number of
> seconds past midnight into a time?

Try your_date::timestamptz + your_seconds * interval '1 sec', e.g.,

test=# select current_date::timestamptz, current_date::timestamptz +
1000 * interval '1 sec';
timestamptz | ?column?
------------------------+------------------------
2005-12-18 00:00:00+09 | 2005-12-18 00:16:40+09
(1 row)

> On a related note is there some reason why
> interval + int
> does not result in the interval plus int number
> of seconds?

Why should the int necessarily represent seconds and not some other
amount of time? It's just a unit-less value.

Michael Glaesemann
grzm myrealbox com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karl O. Pinc 2005-12-18 04:25:05 Converting seconds past midnight to a time
Previous Message Greg Stark 2005-12-18 02:33:09 Re: is this a bug or I am blind?

Browse pgsql-patches by date

  From Date Subject
Next Message Karl O. Pinc 2005-12-18 04:25:05 Converting seconds past midnight to a time
Previous Message Bruce Momjian 2005-12-17 21:59:45 Re: [BUGS] Solaris cc compiler on amd: PostgreSQL does not