我找不到任何有用的技术来将datetime转换为十进制与MSDN上的CONVERT。 有人可以帮助我吗?
更新: 要清楚,我需要小数部分好(因此十进制类型)。所以从9点到10点半应该回到我1.5。
解决方案DATEDIFF(小时, start_date,end_date)将给出 start_date 和 end_date 之间的小时边界数
如果您需要小数小时数,可以使用 DATEDIFF 以更高的分辨率划分结果:
DATEDIFF(第二,start_date,end_date)/ 3600.0MSDN上提供 DATEDIFF 的文档:
msdn.microsoft/en- us / library / ms189794%28SQL.105%29.aspx
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?
UPDATE: 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.0The documentation for DATEDIFF is available on MSDN:
msdn.microsoft/en-us/library/ms189794%28SQL.105%29.aspx
更多推荐
如何在SQL Server中计算两个日期之间的小时差(小数)?
发布评论