date query (1 Viewer)

kitty77

Registered User.
Local time
Today, 17:09
Joined
May 27, 2019
Messages
712
I have a due date field. I would like to return records 30 days before the due date.

thanks...
 

Isaac

Lifelong Learner
Local time
Today, 14:09
Joined
Mar 14, 2017
Messages
8,777
You could test records where Today() >= DateAdd(subtract 30 days from due date)
 

isladogs

MVP / VIP
Local time
Today, 22:09
Joined
Jan 14, 2017
Messages
18,217
For exactly 30 days before, use .... WHERE Date()+30 = DueDate
Or perhaps you meant .... WHERE Date()+30 >= DueDate
 

kitty77

Registered User.
Local time
Today, 17:09
Joined
May 27, 2019
Messages
712
For exactly 30 days before, use .... WHERE Date()+30 = DueDate
Or perhaps you meant .... WHERE Date()+30 >= DueDate
I'm looking for 30 days before due date.... Wouldn't that be -30?
 

isladogs

MVP / VIP
Local time
Today, 22:09
Joined
Jan 14, 2017
Messages
18,217
If due date is 30 days in the future from today then Date()+30 = DueDate or if you prefer DueDate-30 = Date() which is the same thing
 

kitty77

Registered User.
Local time
Today, 17:09
Joined
May 27, 2019
Messages
712
If due date is 30 days in the future from today then Date()+30 = DueDate or if you prefer DueDate-30 = Date() which is the same thing
Not sure we are talking the same... So, I have a due date field. Let's say the due date is 6/1/2021. I would like to return records that are 30 days before the due date. So it would be 5/1/2021. Does that make sense?
 

isladogs

MVP / VIP
Local time
Today, 22:09
Joined
Jan 14, 2017
Messages
18,217
Kitty
Yes we were talking about the same thing.
Your initial post suggested records where due date was 30 days from today rather than some specified due date.

Here's a slightly modified version of what I gave before including the condition added by @CarlettoFed to ensure past order dates are excluded.
The will list any orders where the due date is within the next 30 days

Code:
...WHERE DueDate Between Date() And Date()+30

But...now you appear to have muddled things slightly.
Let's say the due date is 6/1/2021. I would like to return records that are 30 days before the due date. So it would be 5/1/2021. Does that make sense?
On what basis are those records selected. There would need to be some other date field e.g. order date / completion date / despatch date?
If so, you need to modify the Date() function to use the other field concerned instead
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:09
Joined
Feb 19, 2002
Messages
43,266
You should carefully consider the process if you are looking for a date that is exactly 30 days from today. Usually, you would be looking at something in a date range or older/newer than a given date or perhaps in a range with a specific status.
 

Users who are viewing this thread

Top Bottom