I'm trying to use the datediff
function in SQL Server. I'm querying two datetime columns in the same table. I'm trying to get the results where I get hours and minutes in decimal points.
As an example I have this query:
Select
startdatetime, enddatetime,
datediff(minutes, startdatetime, enddatetim) / 60 as 'Hrs worked'
from table1
The results will be something like:
startdatetime | enddatetime | Hrs. worked
2019-02-28 06:00:00.0000000 -08:00 2019-02-28 07:15:00.0000000 -08:00 1
Clearly the difference between startdatetime and enddatetime should be 1.25 not just 1.
Is there anyway to show the decimal value (1.25)?
I also tried:
Select
StartDateTime, EndDateTime,
Convert(decimal(3), (Datediff(minute, StartDateTime, EndDateTime))) / 60 AS 'Hrs Worked'
From Table1
and I do get the Hrs. worked as '1.250000', but I'm unable to drop the trailing zero.
If I use decimal(2)
instead of decimal(3)
, I get this error:
Arithmetic overflow error converting int to data type numeric
Any suggestions?