How to subtract twice 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) 
+6
source share
4 answers
 DECLARE @END_DATE TIME = '' , @START_DATE TIME = '' SELECT CONVERT(TIME,DATEADD(MS,DATEDIFF(SS, @START_DATE, @END_DATE )*1000,0),114) 
+1
source

Using the DATEDIFF function, you will get the difference of two dates / times in the year / month / day / hour / min / sec, as you require.

For example: - DATEDIFF ( MINUTE , startdate , enddate ) - will return diff in minutes

+3
source

You can try using the DATEDIFF function as follows:

 where DATEDIFF(HH,StartWork, EndWork) 
+1
source

You can simply call a query like:

 SELECT CONVERT(varchar,(EndWork- StartWork), 108) FROM tablename 

The output returns the format (hh:mm:ss) .

0
source

All Articles