How to calculate difference in hours (decimal) between two dates in SQL Server?

后端 未结 8 1904
情深已故
情深已故 2020-11-30 23:44

I have to calculate the difference in hours (decimal type) between two dates in SQL Server 2008.

I couldn\'t find any useful technique to convert datetime to decimal

8条回答
  •  不思量自难忘°
    2020-12-01 00:00

    DATEDIFF(minute,startdate,enddate)/60.0)
    

    Or use this for 2 decimal places:

    CAST(DATEDIFF(minute,startdate,enddate)/60.0 as decimal(18,2))
    

提交回复
热议问题