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

CURRENT_DATE function to show prior month data

How do I use the CURRENT_DATE function in DB2 to pull data for the entire past month on the first day of a new month?
This job runs flawlessly daily with the piece of code below, but on the 1st of the month it returns no results:
ACCT_OPEN_DT >(CURRENT DATE - day(current date) days )

*What do I need to modify to make sure that on the 1st of each month, it still shows the prior month's entire data?
Thanks
DB2

Avatar of undefined
Last Comment
saved4use

8/22/2022 - Mon
sathyaram_s

--
ASKER CERTIFIED SOLUTION
sathyaram_s

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Member_2_2484401

Let's see. CURRENT DATE - day(current date) days  will always return the last day of the previous month. If you wanted to return the FIRST day of the previouos month, you could do:

CURRENT DATE - day(current date) days + 1 day - 1 month

HTH,
DaveSlash
Member_2_2484401

If you wanted to return the first day of the current month, you'd do this:

CURRENT DATE - day(current date) days + 1 day
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
saved4use

ASKER
@ sathyaram_s, You are correct, that's exactly what I want.
I've changed my code and will see what happens on 4/1.
Thanks