pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
converting timestamps to ints
3+ messages / 3 participants
[nested] [flat]

* converting timestamps to ints
@ 2001-08-03 03:50 Morgan Curley <mcurley@e4media.com>
  2001-08-03 04:25 ` Re: converting timestamps to ints Josh Berkus <josh@agliodbs.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Morgan Curley @ 2001-08-03 03:50 UTC (permalink / raw)
  To: pgsql-sql

I am writing an app that will need to do some calcs based on differences 
between when a record is first inserted and when it is last updated.
I have seen a lot of column::data-type in this list but can't find the 
relevant section in the documentation. Can anyone point me in the right 
direction?

Currently I am using some code I have seen earlier on this list
select username,  extract( epoch from update_timestamp) - extract( epoch 
from create_timestamp) as time_diff from users;

Is there a simpler way to do this?

Thanks,
Morgan 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: converting timestamps to ints
  2001-08-03 03:50 converting timestamps to ints Morgan Curley <mcurley@e4media.com>
@ 2001-08-03 04:25 ` Josh Berkus <josh@agliodbs.com>
  2001-08-03 05:25   ` Re: converting timestamps to ints Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Josh Berkus @ 2001-08-03 04:25 UTC (permalink / raw)
  To: Morgan Curley <mcurley@e4media.com>; +Cc: pgsql-sql

Morgan,

> I am writing an app that will need to do some calcs based on
> differences 
> between when a record is first inserted and when it is last updated.
> I have seen a lot of column::data-type in this list but can't find
> the 
> relevant section in the documentation. Can anyone point me in the
> right 
> direction?

Hmmm... apparently the docs on date/time data types could use some work.
Or some highlighting.  Or something.  We get this question every week.
I'll do it -- can I submit a FAQ in plain text?

Anyway, Morgan, thanks to Postgres' robust and ANSI-compliant support of
operators, computing intervals is quite simple.  DATETIME is a "pure"
time value; DATE is an integer representation of time, with days as
whole numbers.

Thus:

DATETIME - DATETIME = INTERVAL
DATE - DATE = INTEGER

I don't know what's easier for you to work with; DATE/INTEGER is easier
for math, and DATETIME/INTERVAL is easier for calendar comparisons.

See the docs on data types, functions, and operators at PostgreSQL.org.

-Josh Berkus






______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: converting timestamps to ints
  2001-08-03 03:50 converting timestamps to ints Morgan Curley <mcurley@e4media.com>
  2001-08-03 04:25 ` Re: converting timestamps to ints Josh Berkus <josh@agliodbs.com>
@ 2001-08-03 05:25   ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-08-03 05:25 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: Morgan Curley <mcurley@e4media.com>; pgsql-sql

"Josh Berkus" <josh@agliodbs.com> writes:
> Hmmm... apparently the docs on date/time data types could use some work.
> Or some highlighting.  Or something.  We get this question every week.
> I'll do it -- can I submit a FAQ in plain text?

Go for it --- more docs always welcome ;-)

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-08-03 05:25 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-08-03 03:50 converting timestamps to ints Morgan Curley <mcurley@e4media.com>
2001-08-03 04:25 ` Josh Berkus <josh@agliodbs.com>
2001-08-03 05:25   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox