DateDiff to output hours and minutes

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

    If you want 08:30 ( HH:MM) format then try this,

    SELECT EmplID
        , EmplName
        , InTime
        , [TimeOut]
        , [DateVisited]
        ,  RIGHT('0' + CONVERT(varchar(3),DATEDIFF(minute,InTime, TimeOut)/60),2) + ':' +
          RIGHT('0' + CONVERT(varchar(2),DATEDIFF(minute,InTime,TimeOut)%60),2)
          as TotalHours from times Order By EmplID, DateVisited
    

提交回复
热议问题