DateDiff to output hours and minutes

后端 未结 12 2018
半阙折子戏
半阙折子戏 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:33

    Divide the Datediff in MS by the number of ms in a day, cast to Datetime, and then to time:

    Declare @D1 datetime = '2015-10-21 14:06:22.780', @D2 datetime = '2015-10-21 14:16:16.893'
    
    Select  Convert(time,Convert(Datetime, Datediff(ms,@d1, @d2) / 86400000.0))
    

提交回复
热议问题