How to get seconds between two dates in SQL Server?

I had this MySQL code

DELETE FROM UserError WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(date) > 86400

What is equivalent to this MySQL code in SQL Server?

+4
source share
4 answers

You can use lateiff

DELETE FROM UserError WHERE 
Datediff(s, [date], getdate()) > 86400
+3
source

You can use DateDiff for this. It looks like this:

DateDiff(datePart,startDate,endDate)
0
source
DATEDIFF ( ss , startdate , enddate )
0
source

Try the following:

SELECT DATEDIFF(second, '2005-12-31 23:59:59.9999999', '2006-01-01 00:00:00.0000000'); 

--Syntax
       DATEDIFF ( datepart , startdate , enddate )
0
source

All Articles