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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Getdate() help

Author  Topic 

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2006-02-10 : 14:43:03
Hey All,

I want to retrieve rows that are 1 week prior to the current date. I know the query will involve the Getdate() function. Any help is appreciated.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-02-10 : 15:24:27
Do you mean the entire previous week through today?
Or for 1 day a week ago?

This would be inclusive of all day starting 1 week ago to midnight tonight:

where <DateColumn> >= dateadd(day, datediff(day, 0, getdate()-7), 0) --starting one week ago at 00:00:00.000
and <DateColumn < dateadd(day, datediff(day, 0, getdate()+1), 0) --before 12:00 AM tomorrow morning (all day today)

--see the values
select dateadd(day, datediff(day, 0, getdate()-7), 0) --one week ago at 00:00:00.000
select dateadd(day, datediff(day, 0, getdate()+1), 0) --befor 12:00 tomorrow morning


Be One with the Optimizer
TG
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2006-02-10 : 15:54:26
This works perfectly!! Thanks
Go to Top of Page
   

- Advertisement -