Mohammad  Saadeh Mohammad Saadeh - 7 months ago 16
SQL Question

how to subtract two time in sql server?

So I don't know how to subtract two

time(hh:mm:ss)
in sql server.

This is my statement:

where
( CONVERT(TIME(7), [EndWork], 102)) - ( CONVERT(TIME(7), [StartWork], 102)) <
CONVERT(TIME(7), ' 8:30:00', 102)

Answer
DECLARE @END_DATE TIME = '' ,    
     @START_DATE  TIME = ''
     SELECT CONVERT(TIME,DATEADD(MS,DATEDIFF(SS, @START_DATE, @END_DATE )*1000,0),114)
Comments