21

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Fedor Ivanov
  • 241
  • 1
  • 2
  • 5
  • In MSSQL, you need to use DATEDIFF function. Check this link: http://stackoverflow.com/questions/13577898/sql-time-difference-between-two-dates-result-in-hhmmss – Paresh J Nov 20 '14 at 05:02

4 Answers4

43

You can use datediff

DELETE FROM UserError WHERE 
Datediff(s, [date], getdate()) > 86400
radar
  • 13,270
  • 2
  • 25
  • 33
5

Try this:

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

--Syntax
       DATEDIFF ( datepart , startdate , enddate )
Dhwani
  • 7,484
  • 17
  • 78
  • 139
3

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

DateDiff(datePart,startDate,endDate)
danish
  • 5,550
  • 2
  • 25
  • 28
1
DATEDIFF ( ss , startdate , enddate )
Krish KvR
  • 1,034
  • 4
  • 11
  • 18