Query Data Based On Year/Month

crhodus

Registered User.
Local time
Today, 17:54
Joined
Mar 16, 2001
Messages
257
This is probably a stupid question, but I can't find any info on how to query data from my table based on a year. I have a table that contains dates in the following format: mm/dd/yyyy. I want to be able to query all records that have a year of 2004. Can this be done without having to enter a date range such as " MyDate >= 01/01/2004 and MyDate <= 12/31/2004".

I also want to be create a query that will do the same thing for months.

Can anyone help?

Thanks,!
 
For a year, try putting this in your Criteria field:

Year([YourField])=2004

Or whatever the year is.

Look in Access help under "Year" or "Examples of Expressions" for more info.
 
Thanks for your help. This bit of information allowed me to build the following query:

SELECT
(IIf(Year([TotalVisits.Visits])=Null,Null,Year([TotalVisits.Visits]))) AS VisitYear,
(IIf(Month([TotalVisits.Visits])=Null,Null,Month([TotalVisits.Visits]))) AS VisitMonth
FROM TotalVisits;
 

Users who are viewing this thread

Back
Top Bottom