Extract month from a date field

J

John Conklin

Hello all,

I want to set a date criteria for a query and need some help.

I want the user to enter the month they want the report for and use that to
pull all the records that have a close date that fell in that month.

Any help or suggestions greatly appreciated.

Thanks,
~John
 
R

rowiga

You could use DatePart in the criteria row for the date field that you're
querying. I think you would need to ask for the month and the year. The SQL
would be something like:

SELECT YourTable.YourDateField, OtherFields that apply
FROM YourTable
WHERE (((DatePart('m',[YourDateField]))=[Enter Month Number]) AND
((DatePart('yyyy',[YourDateField]))=[Enter Year YYYY]))
 
D

Douglas J. Steele

What do you want: the month number (1, 2, 3, ... 12), or its name?

For the former, use Month([MyDateField]). For the latter, use
Format([MyDateField], "mmm") to get Jan, Feb, Mar, or Format([MyDateField],
"mmmm") to get January, February, March
 
Top