Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 574
user1558927 Avatar asked Sep 07 '25 08:09

user1558927


1 Answers

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'
like image 197
Gordon Linoff Avatar answered Sep 10 '25 05:09

Gordon Linoff