在SQL中找出日期时间和时间之间的差异

时间:2017-03-25 17:59:28

标签: sql sql-server

我有一个日期时间变量

2017-03-10 13:05:00.000

和时间变量

12:00:00.0000000

我需要找到日期时间和日期时间日期之间的差异,所以我得到1小时5分钟。

3 个答案:

答案 0 :(得分:2)

Declare @D datetime = '2017-03-10 13:05:00.000'
Declare @T time     = '12:00:00.0000000'

Select AsMinutes = DateDiff(MINUTE,@T,cast(@D as time))
      ,AsTime    = Format(DateAdd(MINUTE,DateDiff(MINUTE,@T,cast(@D as time)),0),'HH:mm')
      ,AsString  = replace(Format(DateAdd(MINUTE,DateDiff(MINUTE,@T,cast(@D as time)),0),'H x1 m')+' minutes','x1','hour')

返回

AsMinutes   AsTime  AsString
65          01:05   1 hour 5 minutes

答案 1 :(得分:1)

选择datediff(分钟,演员阵容('2017-03-10 13:05:00.000'作为时间)  ,施放('12:00:00.0000000'作为时间))

答案 2 :(得分:0)

嗯。嗯。 。

scrollView.AddView(linearLayout);
SetContentView(scrollView);

您可能希望将结果转换回时间数据类型。