Subtract two time values in ms sql server 2008
You can use DATEDIFF()
:
SELECT DATEDIFF(Day, startDate, endDate)
FROM table
SELECT DATEDIFF(Second, date, GETDATE())
FROM table
DECLARE @END TIME = '16:00:00.0000000' ,
@START TIME = '01:00:00.0000000'
SELECT convert(TIME,dateadd(ms,DateDiff(ss, @START, @END )*1000,0),114)
following expression works for me
declare @starttime Time, @endtime Time
set @starttime='18:45'
set @endtime='22:45'
select DATEDIFF(HH,@starttime, @endtime)
output: 4