View Full Version : Query Data Based On Year/Month


crhodus
08-05-2004, 09:49 AM
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,!

monkeytunes
08-05-2004, 10:04 AM
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.

crhodus
08-05-2004, 11:23 AM
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;