|
-
Aug 24th, 2005, 09:04 AM
#1
Thread Starter
Hyperactive Member
date less x days in SQL[resolved]
Guys,
I'm sure this is straightforward enough but my brain hurts at the moment.
I want to run a query that gives me data for the last 7 days/month or whatever.
So I need to do something like:
select * from tblcounterv3
where countdate between ('a date a month ago' and convert(varchar,getdate(),103)
It's the 'a date a month ago' that I don't know how to work out.
Hope this makes some sense!
Cheers
Peter
Last edited by thebloke; Aug 25th, 2005 at 04:03 AM.
Reason: resolved
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Aug 24th, 2005, 09:11 AM
#2
Re: date less x days in SQL
now-7
or whatever the equivalent to now is in whichever db you are using...
1 = 1 day (ish) so a date held as a date (number) minus 1 is yesterdays.
If you are in vb/vba use the immediates window:
Code:
?clng(cdate("24 Aug 2005"))
?cdate(clng(cdate("24 Aug 2005"))-1)
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 24th, 2005, 09:41 AM
#3
Re: date less x days in SQL
From the Convert I guess you are using SQL Server, which supports DateAdd, eg:
Code:
between (DATEADD(month, -1, getdate()) and convert(varchar,getdate(),103)
-
Aug 24th, 2005, 11:02 AM
#4
Thread Starter
Hyperactive Member
Re: date less x days in SQL
Thanks chaps, very helpful as always!
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|