Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get difference from two timestamp in DB2?

Tags:

sql

db2

i have a requirement in which i have to get time difference of two timestamp in hours and than later find an average of the hours.

i am using below query to find difference of two timestamp but it does not give exact result it gives approx result. do we have any other solution to achieve the same.My two time stamps are as( LAST_MODIFIED_DATETIME - 2016-11-30 15:39:01.131 CREATE_DATETIME - 2016-07-01 17:25:52.375)

select timestampdiff(8, char(LAST_MODIFIED_DATETIME-CREATE_DATETIME)) as total_time from test_table where name='some name';
like image 457
Rahul Avatar asked Sep 13 '25 16:09

Rahul


1 Answers

Use the built-in Db2 function HOURS_BETWEEN()

https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0061478.html

like image 70
Paul Vernon Avatar answered Sep 16 '25 05:09

Paul Vernon