DateDiff to output hours and minutes

后端 未结 12 1973
半阙折子戏
半阙折子戏 2020-12-09 09:47

my code gives TOTAL HOURS in hours, but i am trying to output something like

TotalHours 
  8:36

where 8 represents hour part and 36 repres

12条回答
  •  一生所求
    2020-12-09 10:18

    Very simply:

    CONVERT(TIME,Date2 - Date1)
    

    For example:

    Declare @Date2 DATETIME = '2016-01-01 10:01:10.022'
    Declare @Date1 DATETIME = '2016-01-01 10:00:00.000'
    Select CONVERT(TIME,@Date2 - @Date1) as ElapsedTime
    

    Yelds:

    ElapsedTime
    ----------------
    00:01:10.0233333
    
    (1 row(s) affected)
    

提交回复
热议问题