Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Records By Month

Status
Not open for further replies.

01jeffro

Technical User
Jun 11, 2001
8
US
I have a table, and I want to run a query to select records based on the month. (i.e. choose records for May through September for all the years I have in my database.) My date is formated mmm yy, so I type in the month and year, and it stores the date as the first day of the month. I think that is stored as the frist day anyway.

Thanks,
Jeffro
 
Put this in the queries Criteria box under your Date field
Between [Enter Starting Date] And [Enter Ending Date]

you need to key in 3/1/01 for the first box
and 9/30/01 for the second box DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
Thanks for your reply, but I want certain months from all years (May 98, May 99, May 00, Jun 98, Jun 99, Jun 00, etc) not just for one year. I thought about it, and put in {like "5/*"} and that gets me all of the mays, then just do ORs for the other months, but I would like to do it with only having to enter the start month and end month.

Thanks,
Jeffro
 
Where do you want to run the query? If in a form/report, you can setup the query when the form/report loads. You can fill an array with the 12 month strings, then from the start date (which I assume will be given in mmm yy format), match to get the start month, concatenate the year, and loop through the months, concatenate the appropriate years, and run the query.

If you just want it to select from the list, use the following:

SELECT *
FROM [tableName]
WHERE Date In ('May 98','May 99','May 00','Jun 98','Jun 99','Jun 00')

The data gets selected when the date string occurs in the list. Maybe that is what you are looking for.

Hope that helps some.

Crater
 

Why not use the month function?

Select * From Tbl
Where month(TheDate)=5

Or

Select * From Tbl
Where month(TheDate) Between 5 and 9
Terry Broadbent


"The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge." - Daniel J Boorstin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top