Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

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
0
saved4use
Asked:
saved4use
  • 2
  • 2
1 Solution
 
sathyaram_sCommented:
--
0
 
sathyaram_sCommented:
so, on any day of the month you want results for this month ..

ie, when run on 13th of march, you want everything from 1st of march.

if you run on 1st of april, you want everything from 1st of march to 31st of march.

is my assumption right?

if it is, try


 ACCT_OPEN_DT >(case when day(current date)=1 then (CURRENT DATE - 1 month - 1 day) else (CURRENT DATE - day(current date) days ) end)

Open in new window

0
 
Dave FordSoftware Developer / Database AdministratorCommented:
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
0
 
Dave FordSoftware Developer / Database AdministratorCommented:
If you wanted to return the first day of the current month, you'd do this:

CURRENT DATE - day(current date) days + 1 day
0
 
saved4useAuthor Commented:
@ 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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now