This month and the past 12 months

octatyan

Registered User.
Local time
Yesterday, 20:48
Joined
Jan 10, 2003
Messages
36
Hi all,

I need help in writing an Access SQL query that selects today's MONTH and shows all records that have fall on or between todays month and the past 12 months. The records have dates in the format of mmddyyyy. I'm stuck and can't find anything on the internet. I probably I just need help in the WHERE section. Something like:

WHERE date is between today and today-12months

I can't find anything helpful on the net to help with this syntax.

Any help is greatly appreciated.
 
Last edited:
Look up the DateAdd() function in the help file.

Bob
 
How about

Between DateAdd("m",-12,Date()) AND Date()
 
Paul-

I've got a problem with this--not with your response, which was right on target--but with folks who use forums as their personal help files.

Just as a test, I did a search entering 'Add year'. It returned 320 responses. Surely more than one of them is going to point the way to resolving the problem.

At some point, folks have to abandon the '...please help me, I'm a newbie' approach and start to take responsibility for conducting their own searches and developing their own solutions.

What do you think?

Bob
 
Actually I agree with you Bob. We must have posted at the same time, because I wouldn't have posted anything if I'd seen your response. I do believe in "teaching how to fish" more than "giving fish". I suppose the level of my answer depends on my mood. In this case I went a little farther than I had to.
 
raskew said:
Paul-

I've got a problem with this--not with your response, which was right on target--but with folks who use forums as their personal help files.

Just as a test, I did a search entering 'Add year'. It returned 320 responses. Surely more than one of them is going to point the way to resolving the problem.

At some point, folks have to abandon the '...please help me, I'm a newbie' approach and start to take responsibility for conducting their own searches and developing their own solutions.

What do you think?

Bob

Bob, Paul, thanks for the help. Your first responses were perfect.

But if you're tired of "catching the fish for people" then all you have to do is just stop. Or just point people in the right direction. Which is exactly what you did in your first post Bob. So looks like your gripe is solved.

I am a newbie and not ebarrassed to admit it. I've looked in the Help section (using both the index AND the paperclip guy) and don't find anything useful. So I'm not sure where or how you found the "320 responses". Maybe I'm just not looking in the right area or whatever (which would affirm my newbie-ness).

I tend to dislike Microsoft help files because they tend to be too techy.
I prefer talking to real people that speak in "people-talk" so it's more understandable. If I can't find tutorials on the Internet, then I have to turn to forums with a direct question.

My problem with finding a tutorial on the Internet is because I don't even know what the right "term" to search for would be. I obviously now know it is "dateadd". Thanks
 
pbaldy said:
How about

Between DateAdd("m",-12,Date()) AND Date()

Paul, thanks for the response. This works, except I had to use GETDATE instead of DATE. When I tried to use DATE it gave me an error saying that it's not a correct function.

:confused:

I'm using SQL in Access 2002. Just wondering where the mix up is?
 
GETDATE is the SQL Server (T-SQL) equivalent of Date() (actually Now()) in Access. Are you doing this in SQL Server (or an ADP)?
 

Users who are viewing this thread

Back
Top Bottom