Months are different from days

K

Kevbro7189

I have a query that looks at a table with a list of dates, and data. I want
to use the query to pull out everything with in the past 3 months (not days
like I have now >(Now()-90). I’m trying to understand expressions in Access
so an explanation would be appreciated.
 
F

fredg

I have a query that looks at a table with a list of dates, and data. I want
to use the query to pull out everything with in the past 3 months (not days
like I have now >(Now()-90). I¢m trying to understand expressions in Access
so an explanation would be appreciated.

The Now() function includes the time of day and will therefore return
different record depending upon the time of day the query is run.
Use Date().

Within the last 3 months:

Between DateAdd("m",-3,Date()) and Date()

The above will work fine.... unless your data includes the time of day
as well as the date.
In that case you must add 1 day to the end date of the criteria:

Between DateAdd("m",-3,Date()) and DateAdd("d",1,Date())
 
K

Klatuu

If the field to be compared does contain time, a more accurate test would be:
DateValue([SomeDateField]) Between DateAdd("m",-3,Date()) and Date()
 
K

Kevbro7189

Thank you for your help. It worked

fredg said:
The Now() function includes the time of day and will therefore return
different record depending upon the time of day the query is run.
Use Date().

Within the last 3 months:

Between DateAdd("m",-3,Date()) and Date()

The above will work fine.... unless your data includes the time of day
as well as the date.
In that case you must add 1 day to the end date of the criteria:

Between DateAdd("m",-3,Date()) and DateAdd("d",1,Date())
 
Top