pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Time difference without intervals
6+ messages / 3 participants
[nested] [flat]

* Time difference without intervals
@ 2002-11-08 18:20 Roberto Mello <rmello@cc.usu.edu>
  2002-11-08 18:59 ` Re: Time difference without intervals Bruno Wolff III <bruno@wolff.to>
  2002-11-08 21:11 ` Re: Time difference without intervals Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 6+ messages in thread

From: Roberto Mello @ 2002-11-08 18:20 UTC (permalink / raw)
  To: pgsql-sql

I saw this question on another PG mailing list, and I don't know how to
answer. I've tried casting the interval to a timestamp, but that doesn't
seem to be supported in 7.2. Does anyone have an answer?

Is there any way to make a timestamp difference operation not return an
interval? I'd like to get hours, minutes and seconds only, not the "1 day"
or whatnot.

lbn-dev=# select now() - '2002-11-07 7:42'::timestamp;
       ?column?        
-----------------------
 1 day 02:01:57.987838
(1 row)


Thanks,

-Roberto

-- 
+----|        Roberto Mello   -    http://www.brasileiro.net/  |------+
+       Computer Science Graduate Student, Utah State University      +
+       USU Free Software & GNU/Linux Club - http://fslc.usu.edu/     +
TAGLINE NO ESPELHO ยค OHLEPSE ON ENILGAT



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

* Re: Time difference without intervals
  2002-11-08 18:20 Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
@ 2002-11-08 18:59 ` Bruno Wolff III <bruno@wolff.to>
  1 sibling, 0 replies; 6+ messages in thread

From: Bruno Wolff III @ 2002-11-08 18:59 UTC (permalink / raw)
  To: Roberto Mello <rmello@cc.usu.edu>; +Cc: pgsql-sql

On Fri, Nov 08, 2002 at 11:20:02 -0700,
  Roberto Mello <rmello@cc.usu.edu> wrote:
> 
> Is there any way to make a timestamp difference operation not return an
> interval? I'd like to get hours, minutes and seconds only, not the "1 day"
> or whatnot.

When you take a difference of two timestamps, you are going to get an
interval that does not have a year, month difference component.

You can get the interval value in seconds by using
extract(epoch from interval).

You can then further manipulate this value to get hours, minutes and seconds.



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

* Re: Time difference without intervals
  2002-11-08 18:20 Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
@ 2002-11-08 21:11 ` Tom Lane <tgl@sss.pgh.pa.us>
  2002-11-09 15:52   ` Re: Time difference without intervals Bruno Wolff III <bruno@wolff.to>
  2002-11-11 05:17   ` Re: Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
  1 sibling, 2 replies; 6+ messages in thread

From: Tom Lane @ 2002-11-08 21:11 UTC (permalink / raw)
  To: Roberto Mello <rmello@cc.usu.edu>; +Cc: pgsql-sql

Roberto Mello <rmello@cc.usu.edu> writes:
> Is there any way to make a timestamp difference operation not return an
> interval? I'd like to get hours, minutes and seconds only, not the "1 day"
> or whatnot.

I think your complaint is not that you get an interval, but that you
want it displayed differently.  See to_char() ...

			regards, tom lane



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

* Re: Time difference without intervals
  2002-11-08 18:20 Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
  2002-11-08 21:11 ` Re: Time difference without intervals Tom Lane <tgl@sss.pgh.pa.us>
@ 2002-11-09 15:52   ` Bruno Wolff III <bruno@wolff.to>
  1 sibling, 0 replies; 6+ messages in thread

From: Bruno Wolff III @ 2002-11-09 15:52 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Roberto Mello <rmello@cc.usu.edu>; pgsql-sql

On Fri, Nov 08, 2002 at 16:11:05 -0500,
  Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Roberto Mello <rmello@cc.usu.edu> writes:
> > Is there any way to make a timestamp difference operation not return an
> > interval? I'd like to get hours, minutes and seconds only, not the "1 day"
> > or whatnot.
> 
> I think your complaint is not that you get an interval, but that you
> want it displayed differently.  See to_char() ...

I looked at to_char before suggesting extract. The problem is that to_char
will only return hours modulo days. His question implied that he was
going to have intervals longer than a day, so I don't believe to_char
will work.



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

* Re: Time difference without intervals
  2002-11-08 18:20 Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
  2002-11-08 21:11 ` Re: Time difference without intervals Tom Lane <tgl@sss.pgh.pa.us>
@ 2002-11-11 05:17   ` Roberto Mello <rmello@cc.usu.edu>
  2002-11-11 05:22     ` Re: Time difference without intervals Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 6+ messages in thread

From: Roberto Mello @ 2002-11-11 05:17 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql

On Fri, Nov 08, 2002 at 04:11:05PM -0500, Tom Lane wrote:
> Roberto Mello <rmello@cc.usu.edu> writes:
> > Is there any way to make a timestamp difference operation not return an
> > interval? I'd like to get hours, minutes and seconds only, not the "1 day"
> > or whatnot.
> 
> I think your complaint is not that you get an interval, but that you
> want it displayed differently.  See to_char() ...

It was not a complaint in any way. I apologize if I came across like that.
It was an honest question.

Thanks for the replies.

-Roberto

-- 
+----|        Roberto Mello   -    http://www.brasileiro.net/  |------+
+       Computer Science Graduate Student, Utah State University      +
+       USU Free Software & GNU/Linux Club - http://fslc.usu.edu/     +
"Apple" (c) Copyright 1767, Sir Isaac Newton.



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

* Re: Time difference without intervals
  2002-11-08 18:20 Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
  2002-11-08 21:11 ` Re: Time difference without intervals Tom Lane <tgl@sss.pgh.pa.us>
  2002-11-11 05:17   ` Re: Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
@ 2002-11-11 05:22     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2002-11-11 05:22 UTC (permalink / raw)
  To: Roberto Mello <rmello@cc.usu.edu>; +Cc: pgsql-sql

Roberto Mello <rmello@cc.usu.edu> writes:
> On Fri, Nov 08, 2002 at 04:11:05PM -0500, Tom Lane wrote:
>> I think your complaint is not that you get an interval, but that you
>> want it displayed differently.  See to_char() ...

> It was not a complaint in any way. I apologize if I came across like that.
> It was an honest question.

Certainly --- I perhaps came across in the wrong way by using the word
"complaint".  Maybe "gripe" or "concern" would've been better.  I was
just trying to identify exactly where the problem was.

			regards, tom lane



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


end of thread, other threads:[~2002-11-11 05:22 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-08 18:20 Time difference without intervals Roberto Mello <rmello@cc.usu.edu>
2002-11-08 18:59 ` Bruno Wolff III <bruno@wolff.to>
2002-11-08 21:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-11-09 15:52   ` Bruno Wolff III <bruno@wolff.to>
2002-11-11 05:17   ` Roberto Mello <rmello@cc.usu.edu>
2002-11-11 05:22     ` 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