I have a sql 2008 database and I am creating a stored procedure that shall check if a datetime is more than 3 hours old but I don’t know how to do it.
Do you have some way to do it?
the datetime is a field in the table.
BR
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Rather than applying
DATEDIFFto the column value, which will negate an index, I suggest using a comparison of the column to an expression (which can use an index).If you want this as a filter:
(If you want only the rows that are newer than 3 hours old, change
<to>or>=.)If you want to return all rows with a column showing whether it is more than 3 hours old: