Sunday, March 24, 2019

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


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(like seconds)  and divide the result:
DATEDIFF(second, start_date, end_date) / 3600.0
The documentation for DATEDIFF is available on MSDN:

No comments:

Post a Comment

Recently Executed queries

 SELECT     txt.TEXT AS [SQL Statement],     qs.EXECUTION_COUNT [No. Times Executed],     qs.LAST_EXECUTION_TIME AS [Last Time Executed],   ...