Current Year

P

PeterK

I have a bunch of data with one date field. I want to be
able to filter the data to include on those records with a
date falling in the current year. What is the criteria?
=???? I don't want to type in the first date of each
year as the years change. I would like it to be
automatic. Can the Date function be used some how?

Thanks
 
D

Dan Artuso

Hi,
You can use the Year function with Date as in:
Year(Date())

Is that what you're after?
You can use a calculated field in your query to filter on the current year:

myYear:Year([yourDateField])

and have a criteria of:
=Year(Date())

HTH
Dan Artuso, MVP
 
S

Steve Schapel

Peter,

In a query, make a new calculated field, the equivalent of...
YearTest: Year([YourDateField])
.... and in the criteria of this column, put...
Year(Date())
 
P

PeterK

Thankyou
-----Original Message-----
Hi,
You can use the Year function with Date as in:
Year(Date())

Is that what you're after?
You can use a calculated field in your query to filter on the current year:

myYear:Year([yourDateField])

and have a criteria of:
=Year(Date())

HTH
Dan Artuso, MVP

I have a bunch of data with one date field. I want to be
able to filter the data to include on those records with a
date falling in the current year. What is the criteria?
year as the years change. I would like it to be
automatic. Can the Date function be used some how?

Thanks


.
 
J

John Spencer (MVP)

Although the other methods are good, I actually prefer to use one of the following.

This one if DateField also contains a time.

WHERE DateField > DateSerial(Year(Date()),1,1) And
DateField < DateSerial(Year(Date())+1,1,1)

or this one if Datefield is just a date with no time.

WHERE DateField Between DateSerial(Year(Date()),1,1) And
DateSerial(Year(Date()),12,31)

Those should be faster since Access does not have to calculate the Year of the
DateField for each record and if there is an index on the datefield the search
can use the index for better performance.

Try
Where Year(Date())=Year([MyDateField])

HTH
Grant

PeterK said:
I have a bunch of data with one date field. I want to be
able to filter the data to include on those records with a
date falling in the current year. What is the criteria?
year as the years change. I would like it to be
automatic. Can the Date function be used some how?

Thanks
 
S

Steve Schapel

Cool, John. Thanks for this enlightenment. I never thought of the
performance aspect.
 
Top