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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to pull data for only current month

Status
Not open for further replies.

Agent001

IS-IT--Management
Joined
Jan 24, 2004
Messages
1
Location
US
I could use some help. I've been developing flat sites for some time now and am venturing into databases. I'm getting stuck trying to pull results out of a database where I only want the current months events to display.

Please help :)


Here is my current query
sql = "select * from tEvents ORDER BY (Start_Date) DESC"


It works beautifully however it displays all records in the database. I've tried several WHERE statements and just can't form the string correctly.

Thank You,


Agent001
Undercover Computers
 
sql = "select * from tEvents WHERE Year(Start_Date) = Year(Date()) and Month(Start_Date) = Month(Date()) ORDER BY (Start_Date) DESC"

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
If you set up an alias of CurrentMonth and apply the Month function to you date field then supply the Month(Now()) for the criteria of the CurrentMonth field you should get what you need.

The SQL looks like this -

SELECT Table3.DATE, Month([DATE]) AS CurrentMonth
FROM Table3
WHERE (((Month([DATE]))=Month(Now())));
 
Duane's solution is better. I was thinking all the data would be current year and I should not have assumed that.

How this helps.

Steve
 
The Format function should work for what you need.

Where Format(Start_Date,"mm/yy") = "05/03"

Where Format(Start_Date,"mm/yyyy") = "05/2003"

'- Current Month
Where Format(Start_Date,"mm") = Format(Now(),"mm")

 
I thought about the Format() function however the original posting mentioned "flat sites" which made me think the query was being used in ASP or other. I'm not sure which functions from Access would be supporteed in ASP or other.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
If it is ASP, I believe the Format function is supported since VB Scripting uses a lot of the same functions as VBA. One exception I ran across was NZ function which was not available in VB Scripting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top