简体   繁体   中英

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.

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. 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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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