current year in a query

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

Guest

I need a query that selects anyone who has a date which the date is in this
year

plus all people whos date is last year

how do i do this
 
To get the current year you can use this
Select * From TableName Where Year(DateField) = Year(Date())

To get the Prev year you can use this
Select * From TableName Where Year(DateField) = Year(Date()) - 1

To get both

Select * From TableName Where Year(DateField) = Year(Date()) Or
Year(DateField) = Year(Date()) - 1
 
Database User said:
I need a query that selects anyone who has a date which the date is in this
year

plus all people whos date is last year

how do i do this

SELECT * FROM TableName
WHERE DateField
BETWEEN DateSerial(Year(Date())-1, 1, 1)
AND DateSerial(Year(Date()), 12, 31)
 
The criteria would probably be
Field: YourDateField
Criteria: Between DateSerial(Year(Date()) -1,1,1) and
DateSerial(Year(Date()),12,31)

That should return all records where YourDateField is between the Jan 1 of
the year prior to the current year (Jan 1, 2004) and the end of the current
year (Dec 31, 2005). On January 1, 2006 this will criteria will give you
all records from Jan 1, 2005 to Dec 31, 2006.

If that is not what you want, post back with an expanded explanation of what
you do want.
 
Back
Top