Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retrieve rows that are less than one week old

Author  Topic 

vermorel
Starting Member

26 Posts

Posted - 2006-05-14 : 05:21:46
I have a table MyTable that contains two fields MyData and CreationTime. I would like to write a query
SELECT MyData FROM MyTable 
WHERE CreationTime < less than one week from now

Does anyone know the real syntax for that?

Thanks in advance,
Joannès

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-14 : 05:26:45
SELECT MyData FROM MyTable
WHERE CreationTime < DateAdd(dd,-7,GetDate())

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2006-05-14 : 13:13:01
Figure out if you want the one week from right now, or one week from the beginning of the day. Depending on if the CreationTime has time included, that can make a difference in how you structure the query. You might want to use the convert function or a time modifier to get exactly what you need.

See this blog entry: http://weblogs.sqlteam.com/derrickl/archive/2005/01/08/3959.aspx

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-15 : 02:55:29

SELECT MyData FROM MyTable
WHERE CreationTime < DateAdd(day,Datediff(day,0,getdate()),-7)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -