Unix Technical Forum

Re: Duration betweeen 2 timestamps

This is a discussion on Re: Duration betweeen 2 timestamps within the pgsql Novice forums, part of the PostgreSQL category; --> Phil - you can subtract two timestamps very easily in Postgres, giving you an interval. You can also use ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 08:29 PM
Schuhmacher, Bret
 
Posts: n/a
Default Re: Duration betweeen 2 timestamps

Phil - you can subtract two timestamps very easily in Postgres, giving
you an interval. You can also use the age() function. You probably
already knew that, though.

Sounds like your bigger problem is how to figure out the "in succession"
bit. Are you trying to figure the relative difference between the
timestamp in row 2 vs. row 1, row 3 vs. row 2, row 4 vs. row 3, etc? Or
is your second timestamp always going to be now()?

BTW, is it necessary to store the difference? It's generally bad
practice to store something you can compute unless the table is so large
that the disk costs and CPU time of storing/indexing the data outweigh
the CPU costs to calculate it. OTOH, if, when you insert the new row
you find the maximum timestamp already in the table, you can lick the
problem I highlighted above as the max(event_date) becomes your second
timestamp.

From your Java pgm, call a function in Postgres and let Postgres do all
the work.

Rgds,

Bret

> -----Original Message-----
> From: pgsql-novice-owner@postgresql.org
> [mailtogsql-novice-owner@postgresql.org] On Behalf Of phil campaigne
> Sent: Friday, February 04, 2005 10:35 AM
> To: pgsql-novice@postgresql.org
> Subject: [NOVICE] Duration betweeen 2 timestamps
>
> Hi All,
> I have stored event records in Postgresql 7.3.4 and now need
> to calculate the duration between each event in succession.
> I have "record_id" and a" timestamp without time zone"
> columns for each event.
>
> What is a good way to calculate the difference in timestamp
> and store it in the record as duration. I am doing this as
> part of a java application on RH linux 8.0.
>
> My timestamp is of the form "2005-01-30 07:51:29.149458".
> thanks in advance,
> Phil
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:04 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com