user1954418
user1954418

Reputation: 1013

Using DATEDIFF in WHERE clause Condition

I have this query in SQL

WHERE DATEDIFF(DD,[fld_DateResolved],GETDATE()) > 3

What I want to do is, to close tickets after 3 Days in my System, My question is, is this the correct way to query to check if the DATEDIFF of DateResolved and GetDate is Greater than 3?

Thanks

Upvotes: 1

Views: 8459

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300549

Make it S'argable (which means an appropriate index might be used if it exists):

WHERE [fld_DateResolved] <= DATEADD(Day, -3, CAST(GETDATE() as Date))

[Updated: added a cast to Date which assumes you are on SQL Server 2008+]

Upvotes: 8

Related Questions