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)
To calculate the difference between the timestamps in MySQL, use the TIMESTAMPDIFF(unit, start, end) function. The unit argument can be MICROSECOND , SECOND , MINUTE , HOUR , DAY , WEEK , MONTH , QUARTER , or YEAR .
MySQL SUBTIME() Function The SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.
Time subtraction: result = time1 - time2 If MINUTE( TIME2 ) > MINUTE( TIME1 ) then MINUTE( RESULT ) = 60 + MINUTE( TIME1 ) - MINUTE( TIME2 ) and HOUR( TIME2 ) is incremented by 1. HOUR( RESULT ) = HOUR( TIME1 ) - HOUR( TIME2 ) .
To get yesterday's date, you need to subtract one day from today's date. Use GETDATE() to get today's date (the type is datetime ) and cast it to date . In SQL Server, you can subtract or add any number of days using the DATEADD() function. The DATEADD() function takes three arguments: datepart , number , and date .
Using the DATEDIFF function you will get the difference of two dates/time in Year/Month/Day/Hour/Min/Sec as you required.
Eg:- DATEDIFF ( MINUTE , startdate , enddate )
--will return the diff in minutes
You can try to use the DATEDIFF function like this:
where DATEDIFF(HH,StartWork, EndWork)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With