Why is my Date Query not working (1 Viewer)

Wapug

Registered User.
Local time
Today, 17:00
Joined
Apr 14, 2017
Messages
51
It is February 4 and I am trying to query a table to get all items in my ADDDATE field that have been added in the past three months. When I run this query I get items with an add date all the way back to October. What am I doing wrong?
<=DateAdd("m",-3,Date())
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:00
Joined
Aug 30, 2003
Messages
36,127
You've said "less than 3 months ago", not greater than.
 

Wapug

Registered User.
Local time
Today, 17:00
Joined
Apr 14, 2017
Messages
51
wouldn't the past 3 months be <=3
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:00
Joined
Aug 30, 2003
Messages
36,127
Well, this

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

gives you a date 3 months ago:

?DateAdd("m",-3,Date())
11/4/2019

and your criteria is less than or equal to that. From your description, you want greater than that.
 

Wapug

Registered User.
Local time
Today, 17:00
Joined
Apr 14, 2017
Messages
51
so maybe Im saying it wrong. I want my query to return all the items that have an ADDDATE that is within the last 3 months, not the ones that have an ADDDATE 3 months ago so all items in Nov, Dec and Jan.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:00
Joined
Aug 30, 2003
Messages
36,127
So have you tried changing it to:

>=DateAdd("m",-3,Date())
 

Wapug

Registered User.
Local time
Today, 17:00
Joined
Apr 14, 2017
Messages
51
Yes >=DateAdd("m",-3,Date()) that gives me everything from 12-05-19 back through the earliest data of 2019. When I do this <=DateAdd("m",-3,Date()) it gives me all the way back to October 2019. Im not sure what the heck the deal is
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:00
Joined
Aug 30, 2003
Messages
36,127
Either you didn't notice I changed the < to > or your field doesn't have the date/time data type. Can you attach the db here?
 

Wapug

Registered User.
Local time
Today, 17:00
Joined
Apr 14, 2017
Messages
51
You solved my problem! I had the field on the table I was querying set to the wrong type. Thank you so much for your time!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:00
Joined
Aug 30, 2003
Messages
36,127
Happy to help! Yeah, if it was text you were getting an alphabetic comparison, not a date comparison.
 

isladogs

MVP / VIP
Local time
Today, 22:00
Joined
Jan 14, 2017
Messages
18,246
When doing date comparisons in VBA, you need dates in format mm/dd/yyyy. Its not clear to me (and possibly Access) whether 12-05-2019 is 12 May or 5 Dec. Neither is 3 months ago
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:00
Joined
Aug 30, 2003
Messages
36,127
Day late and a pound short. ;)
 

Users who are viewing this thread

Top Bottom