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

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 with ‘CONVERT’ on MSDN.
Can anybody help me with that?

To be clear, I need the fractional part as well (thus decimal type). So from 9:00 to 10:30 it should return me 1.5.


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:

Leave a Reply

Your email address will not be published. Required fields are marked *