timestamp to int

Started by Edwin Grubbsalmost 25 years ago7 messagesgeneral
Jump to latest
#1Edwin Grubbs
egrubbs@rackspace.com

Is there any function for converting a timestamp into an integer with the
unix seconds value? It's really easy to convert in the other direction.

-Edwin

#2Mitch Vincent
mvincent@cablespeed.com
In reply to: Edwin Grubbs (#1)
Re: timestamp to int

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40');

-- and you can replace the timestamp string with the name of a timestamp
column.

The above is in the manual, BTW.

-Mitch

----- Original Message -----
From: "Edwin Grubbs" <egrubbs@rackspace.com>
To: <pgsql-general@postgresql.org>
Sent: Tuesday, June 26, 2001 11:16 AM
Subject: [GENERAL] timestamp to int

Show quoted text

Is there any function for converting a timestamp into an integer with the
unix seconds value? It's really easy to convert in the other direction.

-Edwin

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

#3Tomas Berndtsson
tomas@nocrew.org
In reply to: Mitch Vincent (#2)
Re: timestamp to int

"Mitch Vincent" <mvincent@cablespeed.com> writes:

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40');

-- and you can replace the timestamp string with the name of a timestamp
column.

The above is in the manual, BTW.

Is there a way to do it the other way around, from an integer to a
timestamp?

Tomas

#4will trillich
will@serensoft.com
In reply to: Tomas Berndtsson (#3)
Re: timestamp to int

On Tue, Jun 26, 2001 at 09:22:25PM +0200, Tomas Berndtsson wrote:

"Mitch Vincent" <mvincent@cablespeed.com> writes:

SELECT EXTRACT(EPOCH FROM TIMESTAMP '2001-02-16 20:38:40');

-- and you can replace the timestamp string with the name of a timestamp
column.

The above is in the manual, BTW.

Is there a way to do it the other way around, from an integer to a
timestamp?

of course not. don't be silly.

certainly not date_part or to_char or to_date. they're not
mentioned in the docs, either, so don't bother looking.
(think of the time you'll save.)

in particular, on my debian system, you wouldn't look in
/usr/share/doc/postgresql-doc/html/postgres/postgres.htm
and you wouldn't do

cd /usr/share/doc/postgresql-doc/html/postgres
grep -i epoch *

that would be bad.

--
I'd concentrate on "living in the now" because it is fun
and on building a better world because it is possible.
- Tod Steward

will@serensoft.com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

#5Tomas Berndtsson
tomas@nocrew.org
In reply to: will trillich (#4)
Re: timestamp to int

will trillich <will@serensoft.com> writes:

On Tue, Jun 26, 2001 at 09:22:25PM +0200, Tomas Berndtsson wrote:

Is there a way to do it the other way around, from an integer to a
timestamp?

of course not. don't be silly.

certainly not date_part or to_char or to_date. they're not
mentioned in the docs, either, so don't bother looking.
(think of the time you'll save.)

in particular, on my debian system, you wouldn't look in
/usr/share/doc/postgresql-doc/html/postgres/postgres.htm
and you wouldn't do

cd /usr/share/doc/postgresql-doc/html/postgres
grep -i epoch *

that would be bad.

I sense a touch of sarcasm. Yet, having looked (yes, before I mailed,
and now again after), I still can't find a way to create a timestamp
from an integer. You may call me stupid, but I'd be glad to see how
it's done.

Tomas

#6Alex Pilosov
alex@pilosoft.com
In reply to: Tomas Berndtsson (#5)
Re: timestamp to int

On 30 Jun 2001, Tomas Berndtsson wrote:

certainly not date_part or to_char or to_date. they're not
mentioned in the docs, either, so don't bother looking.
(think of the time you'll save.)

in particular, on my debian system, you wouldn't look in
/usr/share/doc/postgresql-doc/html/postgres/postgres.htm
and you wouldn't do

cd /usr/share/doc/postgresql-doc/html/postgres
grep -i epoch *

that would be bad.

I sense a touch of sarcasm. Yet, having looked (yes, before I mailed,
and now again after), I still can't find a way to create a timestamp
from an integer. You may call me stupid, but I'd be glad to see how
it's done.

Quite strangely, there's no argument for to_date to do conversion from
'seconds since epoch'. At any case, this is how you do it:

select 'epoch'::timestamp + (x || ' seconds')::interval

-alex

#7Tomas Berndtsson
tomas@nocrew.org
In reply to: Alex Pilosov (#6)
Re: timestamp to int

Alex Pilosov <alex@pilosoft.com> writes:

On 30 Jun 2001, Tomas Berndtsson wrote:

certainly not date_part or to_char or to_date. they're not
mentioned in the docs, either, so don't bother looking.
(think of the time you'll save.)

in particular, on my debian system, you wouldn't look in
/usr/share/doc/postgresql-doc/html/postgres/postgres.htm
and you wouldn't do

cd /usr/share/doc/postgresql-doc/html/postgres
grep -i epoch *

that would be bad.

I sense a touch of sarcasm. Yet, having looked (yes, before I mailed,
and now again after), I still can't find a way to create a timestamp
from an integer. You may call me stupid, but I'd be glad to see how
it's done.

Quite strangely, there's no argument for to_date to do conversion from
'seconds since epoch'. At any case, this is how you do it:

select 'epoch'::timestamp + (x || ' seconds')::interval

Thank you. That wasn't too obvious to me, but quite logical when
seeing it now.

Tomas