Current month

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I would like to retrieve all records of the current month. I would like to
do this by specify in the query criteria.
Could someone help me?

Thank you.
Ashley
 
You could use

WHERE Format([MyDateField], "yyyymm") = Format(Date(), "yyyymm")

or

WHERE [MyDateField] BETWEEN DateSerial(Year(Date), Month(Date), 1)
AND DateSerial(Year(Date), Month(Date) + 1, 1)
 
HI Ashley,
There are several ways to do this.
A simple way is (substitute table and field names in the query)

SELECT * FROM myTable WHERE Month(dateFieldInTable)=[Enter the month
number:]

See also Day(), Year(), DateAdd(), DateDiff() functions and Between
operator.

HTH, Graeme.
 
to add with Graeme code
SELECT * FROM myTable WHERE Month(dateFieldInTable)=[Enter the month
number:] and Year(dateFieldInTable)=[Enter the Year:]
 
A different approach which is probably more efficient if you have a lot of
Records in the Table and you index the DateField.

SELECT ...
FROM ...
WHERE ( DateField >= DateSerial(Year(Date()), Month(Date()), 1) )
AND ( DateField < DateSerial(Year(Date()), Month(Date()) + 1, 1) )
 
I have used the following criteria which seems to work.

Field: Year([Date])
Criteria: [Enter Year Required (yyyy)]
&
Field: Month([Date])
Criteria: [Enter Month Required (Dec=12)]

This will give you a popup box asking for the year and a popup box asking
for the month. I have entered the month criteria in the column to the right
of the year criteria.

Good luck
 
Back
Top