DateDiff to output hours and minutes

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

    Just change the

    DATEDIFF(Hour,InTime, [TimeOut]) TotalHours
    

    part to

    CONCAT((DATEDIFF(Minute,InTime,[TimeOut])/60),':',
           (DATEDIFF(Minute,InTime,[TimeOut])%60)) TotalHours 
    

    The /60 gives you hours, the %60 gives you the remaining minutes, and CONCAT lets you put a colon between them.

    I know it's an old question, but I came across it and thought it might help if someone else comes across it.

提交回复
热议问题