Query By Year

T

Tara

How do I query by the year that will be user entered? I
have a date field that I want to be searched and values
returned if they match the year entered.

Thanks in advance!

Tara
 
J

John Spencer (MVP)

Assuming that your user is entering a four-character year, you could use

Field: SomeDate
Criteria: Between DateSerial([What year? (yyyy)],1,1) AND DateSerial([What year?
(yyyy)],12,31)

OR another method that may be slower.

Field: TheYear: Year([Sometable].[SomeDate])
Criteria: [What year? (yyyy)]
 
B

Brian Camire

If the values in your date field may contain a time of day component, you
might want to try something like the following variation on John's
suggestion:
=DateSerial([What year? (yyyy)],1,1) And <DateSerial([What year?
(yyyy)]+1,1,1)

Otherwise, you will omit dates on December 31 that are after midnight.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top