Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 of this MySQL code in SQL Server?

like image 970
Fedor Ivanov Avatar asked Nov 20 '14 04:11

Fedor Ivanov


2 Answers

You can use datediff

DELETE FROM UserError WHERE 
Datediff(s, [date], getdate()) > 86400
like image 161
radar Avatar answered Oct 24 '22 16:10

radar


Try this:

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

--Syntax
       DATEDIFF ( datepart , startdate , enddate )
like image 27
Dhwani Avatar answered Oct 24 '22 15:10

Dhwani