You don't explain what "time decimal" format is. From your example, I'll guess that you mean decimal hours.
A key function in SQL Server for date differences is datediff()
. You can convert the time to seconds using a trick. Add the time to a date, then use datediff()
to get the number of seconds after midnight. After that, the conversion to decimal hours is just arithmetic.
Here is an example:
select datediff(second,
cast('2000-01-01' as datetime),
cast('2000-01-01 ' + '00:00:59' as datetime)
)/3600.0 as DecimalHours
Note the use of the constant 3600.0
. The decimal point is quite important, because SQL Server does integer division on integer inputs. So, 1/2
is 0
, rather than 0.5
.