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

后端 未结 8 1898
情深已故
情深已故 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-11-30 23:55

    DATEDIFF(hour, start_date, end_date) will give you the number of hour boundaries crossed between start_date and end_date.

    If you need the number of fractional hours, you can use DATEDIFF at a higher resolution and divide the result:

    DATEDIFF(second, start_date, end_date) / 3600.0
    

    The documentation for DATEDIFF is available on MSDN:

    http://msdn.microsoft.com/en-us/library/ms189794%28SQL.105%29.aspx

提交回复
热议问题