sipwiz sipwiz - 6 months ago 41
SQL Question

SQL Server select where datetimeoffset older than 1 hour

I know this should be easy and I do it no probelms in mySQL and Postgresql but I'm struggling with SQL Server. I want to select rows with a datetimeoffset field that's over an hour old.

select * from table where mydatetime < getdate() - 1 hour


I've tried dateadd and datediff but can't get it right.

Answer
WHERE mydatetime < DATEADD(hour, -1, SYSDATETIMEOFFSET())

For more see: DATEADD (Transact-SQL)