How to get seconds between two dates in SQL Server?

30,993

Solution 1

You can use datediff

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

Solution 2

Try this:

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

--Syntax
       DATEDIFF ( datepart , startdate , enddate )

Solution 3

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

DateDiff(datePart,startDate,endDate)

Solution 4

DATEDIFF ( ss , startdate , enddate )
Share:
30,993
Fedor Ivanov
Author by

Fedor Ivanov

Updated on July 05, 2022

Comments

  • Fedor Ivanov
    Fedor Ivanov almost 2 years

    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?