If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQl Query to find time diff in minutes from Timestmp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-11, 03:06
Arun Bv Arun Bv is offline
Registered User
 
Join Date: Jun 2011
Posts: 1
Cool SQl Query to find time diff in minutes from Timestmp

hi can anyone tell me how to find time diffe in minutes from timestamp ...

i tried below sql queries but these are not retrieving correct diff in minutes


SELECT TRUNC((86400*(CURRENT TIMESTAMP - ('2011-06-18-05.03.41.300585')))/60)
-60*(TRUNC(((86400*(CURRENT TIMESTAMP - ('2011-06-18-05.03.41.300585')))/60)
/60))
FROM SYSIBM.SYSDUMMY1


SELECT MINUTE(CURRENT TIMESTAMP) - MINUTE('2011-06-15-02.01.56.178837')
FROM SYSIBM.SYSDUMMY1




SELECT CURRENT TIMESTAMP, (CURRENT TIMESTAMP - '2011-06-20-04.25.39.919005')/60

FROM SYSIBM.SYSDUMMY1;



05 WS-TIME-DIFF PIC X(04).
05 BDR-BKT-REQ-TIMESTMP PIC X(26) VALUE '2011-06-15-02.01.56.178837' .
EXEC SQL
SET :WS-TIME-DIFF = MINUTE(CURRENT TIMESTAMP) - MINUTE(BDR-BKT-REQ-TIMESTMP)
END-EXEC



SO IF ANYONE KNEW any other query TO FIND TIME DIFFERENCE FROM TIMESTAMP IN MINUTES ...PLS TELL ME AS SOON AS POSSIBLE
Reply With Quote
  #2 (permalink)  
Old 06-22-11, 05:38
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
scalar function TIMESTAMPDIFF
hope i was quick enough with the answer!!!

you syntax is very poor.
this would also work:
MINUTE(CURRENT_TIMESTAMP - (CURRENT_TIMESTAMP - 4 MINUTES))
__________________
Dick Brenholtz, Ami in Deutschland

Last edited by dbzTHEdinosaur; 06-22-11 at 05:45.
Reply With Quote
  #3 (permalink)  
Old 06-22-11, 05:49
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
are you attempting to determine the interval in minutes between two timestamps
that my be days apart?
__________________
Dick Brenholtz, Ami in Deutschland
Reply With Quote
  #4 (permalink)  
Old 06-22-11, 07:49
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
An example of expression may be...
( DAYS(to_timestamp) - DAYS(from_timestamp) ) * 1440 /* 1440 = 24 Hr x 60 Min */
+ ( MIDNIGHT_SECONDS(to_timestamp) - MIDNIGHT_SECONDS(from_timestamp) ) / 60
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On