tags:

views:

74

answers:

2

Hi

I hope anyone can translate my abstract query.

I want to select * from TABLE where ( [MYDATETIMEROW] < (TODAY - 3 Days)).

Does I have to Convert, cast or use datepart or anything else?.. im confused.

Are there simple rules? I would'nt have problems to do that with linq but simple sql I learned just hardly.

Thank you and best regards.

+1  A: 

You want the DateAdd function to manipulate dates and the GetDate function to get the current date:

SELECT * FROM MyTable WHERE [MyDateTimeRow] < DateAdd(dd, -3, GetDate())
Chris Latta
+2  A: 

In simple terms:

Select * from Table where MyDateTimeRow < dateadd(dd,-3,getdate())

But using getdate() will provide both a date and a time, experience says that this is unlikely to be exactly what you want - you might want to strip the time down and just consider the date portion

Select * From Table where MyDateTimeRow < dateadd(dd, datediff(dd, 0, getdate()) - 3, 0)
Andrew
thx that worked.
snarebold