August 15, 2005 at 8:22 am
I've got a sql query in which I compare the date in a field (called RecordDate) to todays date (got using GETDATE function). I want the query only to apply to records where their RecordDate is 10 days less than todays date.
I want to know what the where clause should e.g.
Select *...
......
WHERE RecordDate = GETDATE + 10
Anyone know what the WHERE Clause should be.
macca
August 15, 2005 at 8:49 am
The basic answer is:
WHERE RecordDate < DATEADD(d, 10, GETDATE())
Depending on specifically how you want to compare the dates you might want to alter that. For lots of great information regarding working with datetime in SQL Server, take a look at these articles:
August 15, 2005 at 8:59 am
And I see now that I misread your question. This should probably be what you are looking for:
WHERE RecordDate BETWEEN DATEADD(d,DATEDIFF(d,0,GETDATE()),-10) AND DATEADD(s, -1, DATEADD(d,DATEDIFF(d,0,GETDATE()),-9))
August 15, 2005 at 9:12 am
Thanks Chris.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply