3

我有这样的查询:

select t.Paydate,t.DelDate,DATEDIFF(MI, t.Paydate,t.DelDate) as Datdiffernce 
from Transaction_tbl t 
where t.transactID=19

我是这样出去的:

Paydate                 DelDate                 Datdiffernce
----------------------- ----------------------- ------------
2013-05-07 18:36:50.000 2013-05-07 18:58:32.000     22

Datedifference我只有 22 块薄荷糖。

而不是得到那个我怎么能得到这种格式的日期差异hh:mm:ss

4

2 回答 2

5

试试这个,

SELECT convert(varchar(10),DATEDIFF(hour,t.Paydate,t.DelDate))+'hr:' 
      +convert(varchar(10),DATEDIFF(minute,t.Paydate,t.DelDate)% 60) + 'mnts:' 
      +convert(varchar(10),DATEDIFF(SECOND,t.Paydate,t.DelDate)% 60) +'seconds'
       AS 'DIFF IN HH:MM:SS'
FROM Transaction_tbl t 
WHERE t.transactID=19  
于 2013-07-18T08:01:26.780 回答
0
Declare @starttime datetime, @endtime datetime, @seconds int

Set @starttime ='2013-10-01 15:05:17'
Set @endtime = '2013-10-01 15:10:16'

set @seconds = DateDiff(second, @starttime, @endtime)
Select Convert(varchar(10), @seconds/3600) + 'hr:'
       +Convert(varchar(10), (@seconds % 3600)/60) + 'mnts:'
       +Convert(varchar(10), (@seconds % 3600) % 60) + 'seconds'

参考:看这里

于 2013-10-01T19:44:55.730 回答