Select to view content in your preferred language

Inbox Query using date field

72
2
Jump to solution
yesterday
Slamon
by
Occasional Contributor

I need some help setting up a query or refining a query for the following logic.

AVO_LASTDATE is the last inspection date

I only want to show inspections where AVO_LASTDATE is greater than or equal to 15 days ago, but not in this month of this year.

For example, if the AVO_LASTDATE is 1/4/2025, I shouldn't see it in the inbox until 2/1/2025.

If AVO_LASTDATE is 1/31/2025, I should see it in the inbox starting 2/15/2025

Inspections have to be at least 15 days apart but I can't do two in the same month.  This is what I have now, but am getting a 400 error.

(CURRENT_DATE - 15 >= AVO_LASTDATE) AND MONTH(AVO_LASTDATE) != MONTH(CURDATE())
AND YEAR(AVO_LASTDATE = YEAR(CURDATE())

0 Kudos
2 Solutions

Accepted Solutions
DavidSolari
MVP Regular Contributor

Your last 15 days logic is backwards, you're mixing CURRENT_DATE with CURDATE() (not a real function), those MONTH and YEAR functions won't work and you're testing for inequality with != instead of <>. Putting that all together with some help from this post:

AVO_LASTDATE > (CURRENT_DATE - 21) AND extract(month from AVO_LASTDATE) <> extract(month from CURRENT_DATE) AND extract(year from AVO_LASTDATE) = extract(year from CURRENT_DATE)

View solution in original post

0 Kudos
Slamon
by
Occasional Contributor

Thanks David,

This appears to have done the trick. 

View solution in original post

2 Replies
DavidSolari
MVP Regular Contributor

Your last 15 days logic is backwards, you're mixing CURRENT_DATE with CURDATE() (not a real function), those MONTH and YEAR functions won't work and you're testing for inequality with != instead of <>. Putting that all together with some help from this post:

AVO_LASTDATE > (CURRENT_DATE - 21) AND extract(month from AVO_LASTDATE) <> extract(month from CURRENT_DATE) AND extract(year from AVO_LASTDATE) = extract(year from CURRENT_DATE)

0 Kudos
Slamon
by
Occasional Contributor

Thanks David,

This appears to have done the trick.