如何从 DB2 中的两个时间戳中获取差异? [英] How to get difference from two timestamp in DB2?

查看:26
本文介绍了如何从 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.

我正在使用下面的查询来查找两个时间戳的差异,但它没有给出确切的结果,它给出了近似结果.我们是否有任何其他解决方案来实现相同的目标.我的两个时间戳为(LAST_MODIFIED_DATETIME - 2016-11-30 15:39:01.131 CREATE_DATETIME - 2016-07-01 17:25:52.375)

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';

推荐答案

很简单,将时间戳转换为小时,如下所示:

It's easy, by converting the timestamp to hours as follows:

(24*DAYS(last_modified_datetime)+MIDNIGHT_SECONDS(last_modified_datetime)/3600)
-
(24*DAYS(create_datetime)+MIDNIGHT_SECONDS(create_datetime)/3600)

这篇关于如何从 DB2 中的两个时间戳中获取差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆