Querying Dates

  • Thread starter Thread starter Nigel
  • Start date Start date
N

Nigel

I know that by using a parameter query I can select dates between 1/1/03 and
31/3/03, but how can I select dates that occur in the first 3 months of every
year?

Thanks
 
Nigel said:
I know that by using a parameter query I can select dates between 1/1/03
and
31/3/03, but how can I select dates that occur in the first 3 months of
every
year?

Thanks

WHERE Month([NameOfDateFieldHere]) < 4
 
If you are asking how to enter a parameter that limits the query to records
form one quarter (all years), type this in the Field row in query design:
DatePart("q", [MyDate])
substituting your field name for MyDate.
In the Criteria row under this field, enter:
[What quarter]

That should respond to values 1 through 4, (and return no records for other
values.) It would be a good idea to delcare the parameter: Parameters on
Query menu, and in the dialog enter:
[What quarter] Integer

Or perhaps you were asking how to show totals for each quarter of each year?
If so, depress the Total button on the toolbar in query design. Access adds
a Total row to the design grid.

In the Field row, enter:
Year([MyDate])
substituting the name of your date field.
Accept Group By in the Total row.

In the next column in the Field row, enter:
DatePart("q", [MyDate])
 
Brendan Reynolds said:
Nigel said:
I know that by using a parameter query I can select dates between 1/1/03
and
31/3/03, but how can I select dates that occur in the first 3 months of
every
year?

Thanks

WHERE Month([NameOfDateFieldHere]) < 4

Or

WHERE [NameOfDateFieldHere] BETWEEN DateSerial(Year(Date), 1, 1) AND
DateSerial(Year(Date), 3, 31)

This should be slightly more efficient, since it only has to invoke the two
DateSerial functions once, as opposed to having to invoke the Month function
for each row in the table. (Probably won't make enough of a difference to be
noticable though!)
 
Back
Top