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
 Getting the last 7 days

Author  Topic 

dingodog
Starting Member

5 Posts

Posted - 2007-01-24 : 11:25:45
Did a bit of searching, but couldn't find it. I'm looking to get data from the past 7 days:

select * from inquiry
where created_date is within the last 7 days

Thanks,

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-24 : 11:29:05
[code]Select * from inquiry
where datediff(day, created_date, getdate())<=7[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-01-24 : 11:35:00
to use an index on created_date use:

declare @From datetime
select @From = SELECT DATEADD(d, DATEDIFF(d, 0, GetDate()), -7)
Select * from inquiry
where created_date >= @From





Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -