简体   繁体   English

DATEDIFF将分钟转换为小数

[英]DATEDIFF convert minutes to decimal

I'm having some problems converting minutes to a decimal even though I've looked at other responses at SO. 我在将分钟转换为小数时遇到了一些问题,尽管我已经查看了SO的其他回复。

select cast(datediff(minute, min(start_time), min(complete_time)) as decimal (10,10)) 
from TRACKED_OBJECT_HISTORY TOH1 
where TOH1.op_name = 'Assembly'

The result returns, but I always get results like 2.00, 4.00, 5.00 instead of numbers like 1.86, 3.99, 5.03. 结果返回,但我总是得到像2.00,4.00,5.00这样的结果而不是像1.86,3.99,5.03这样的数字。 I guess it's converting after the fact (I also tried the convert function to no avail). 我想这是事后的转换(我也试过转换功能无济于事)。 Any thoughts? 有什么想法吗?

Datediff return an integer, not a float or numeric. Datediff返回一个整数,而不是float或numeric。

To get what you want, perhaps you should do the diff in seconds and then divide: 为了得到你想要的东西,也许你应该在几秒钟内完成差异然后除以:

select cast(datediff(second, min(start_time), min(complete_time))/60.0 as decimal (10,10))
from TRACKED_OBJECT_HISTORY TOH1 where TOH1.op_name = 'Assembly'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM