Ingres Community Forums Login Register Ingres.com  

Ingres Community Forum


Go Back   Ingres Community Forums > Ingres Forums > DBA Forum
 

Reply
 
LinkBack Thread Tools Display Modes
Old 2008-11-19   #1 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 14
Default Timestamp question

Hi,

how can I find he number of seconds between two timestamps?

Something like:
select number_of_seconds(eventA - eventB) from myEvents;

Thanks
Ole
oleaka is offline   Reply With Quote
Old 2008-11-19   #2 (permalink)
Ingres Community
 
Join Date: Mar 2007
Location: California
Posts: 76
Default

You can use the function second().
It extracts the second portion of a time or timestamp.
So, the query will be something like:
select second(timestamp_column1) - second(timestamp_column2)
Divya is offline   Reply With Quote
Old 2008-11-19   #3 (permalink)
Ingres Community
 
MagnusG's Avatar
 
Join Date: Mar 2007
Location: Säter, Sweden
Posts: 29
Default

Hi,
This (or something similar depending on exact need) should also work:
select interval ('sec', a.kol2 -b.kol2)
from aa a, aa b
where b.kol1 = 1 and a.kol1 = 2

Regards, Magnus
MagnusG is offline   Reply With Quote
Old 2008-11-19   #4 (permalink)
Junior Member
 
Join Date: Oct 2008
Posts: 14
Default

Hi,

thank you for the quick replies.

Got it to work using interval:
select interval('sec', timestamp('1990-12-12 13:13:13.0')) - interval('sec', timestamp('1990-12-12 13:10:13.0'));
gives the answer 180, as I was looking for.

Regards
Ole
oleaka is offline   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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


© 2009 Ingres Corporation. All Rights Reserved