如何获得两个日期之间的差异,四舍五入为小时 [英] How to get the difference between two dates rounded to hours

查看:48
本文介绍了如何获得两个日期之间的差异,四舍五入为小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,我将说明我想要得到的东西:

I'll illustrate what I would like to get in the following example:

'2010-09-01 03:00:00' - '2010-09-01 00:10:00'

使用TIMEDIFF(),结果为2.这意味着,它没有考虑剩下的50分钟.

Using TIMEDIFF(), we get 2 as a result. This means, it's not considering the 50 minutes left.

在这种情况下,我想要得到的是:50(分钟)/60 = 0.83周期.因此,结果应为2.83,而不是2.

In this case, what I'd like to get is: 50 (minutes) / 60 = 0.83 period. Therefore, the result should be 2.83 and not 2.

推荐答案

select time_to_sec(timediff('2010-09-01 03:00:00', '2010-09-01 00:10:00' )) / 3600;

+-----------------------------------------------------------------------------+
| time_to_sec(timediff('2010-09-01 03:00:00', '2010-09-01 00:10:00' )) / 3600 |
+-----------------------------------------------------------------------------+
|                                                                      2.8333 | 
+-----------------------------------------------------------------------------+

这篇关于如何获得两个日期之间的差异,四舍五入为小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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