Avatar of saved4use
saved4use
Flag for United States of America asked on

DB2 date function between specific dates next month

Every month on the 23rd, I'll run a query whereupon I want to pick up assets that mature between  the 14th of next month and the last day of next month. *For 5/23, it's going to be btwn 6/14 and 6/30.
What date function do I need to use?

<= CURRENT_DATE  + 40 days doesn't work as it still includes 5/23, 5/31, etc.

Thank you for your help.
DB2

Avatar of undefined
Last Comment
sathyaram_s

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
sathyaram_s

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Kent Olsen

Hi Saved,

If you can tolerate a query that's a little flexible, here's one that you can run any time during the month and it will pick the items in that range for next month.

SELECT * FROM sometable
WHERE current_date - (day (current_date - 1 + 13)) days + 1 month <= mature_date
  AND current_date - (day (current_date) -1) days + 2 months > mature_date

Open in new window



Good Luck,
Kent
saved4use

ASKER
Perfect solution! Exactly what I needed.
Thanks!
sathyaram_s

When looking at the output again, I see a mistake in calculating the last day of the month

It should be

dt-(day(dt)-1) days+2 months - 1 day

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck