如何通过数分钟和数分钟获得两个数据时间之间的差异 [英] How to get the difference between two datetimes in hours and minutes

查看:149
本文介绍了如何通过数分钟和数分钟获得两个数据时间之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个这样的数据时间:

  transtime_in,transtime_out 
/ pre>

如何以下列格式获取这些数据时间之间的差异:

  hh:mm 






我使用

  DATEDIFF(hour,transtime_in,transtime_out)

但我只能收到小时。

解决方案

尝试这个 -



查询:

  DECLARE 
@ transtime_in DATETIME
,@transtime_out DATETIME

SELECT
@transtime_in ='2013-05-19 08:58:07.000'
,@transtime_out ='2013-05 -19 16:40:53.000'

SELECT LEFT(CONVERT(VARCHAR(10),@transtime_out - @transtime_in,108),5)
pre>

输出:

  ---- 
07:42


If I have two datetimes like this :

transtime_in, transtime_out

How to get the difference between those datetimes in the following format :

hh:mm


I use

DATEDIFF(hour, transtime_in, transtime_out) 

but i get the hours only .

解决方案

Try this one -

Query:

DECLARE 
      @transtime_in DATETIME
    , @transtime_out DATETIME

SELECT 
      @transtime_in = '2013-05-19 08:58:07.000'
    , @transtime_out = '2013-05-19 16:40:53.000'

SELECT LEFT(CONVERT(VARCHAR(10), @transtime_out - @transtime_in, 108), 5)

Output:

-----
07:42

这篇关于如何通过数分钟和数分钟获得两个数据时间之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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