Oracle; dates- looking for previous month

Hi Experts
I have this statement
select
(case to_char(trunc(sysdate,'mm'),'d') when '7' then trunc(sysdate,'mm')+2 when '1' then trunc(sysdate,'mm')+1 else trunc(sysdate,'mm') end) NEWDATE
from dual

That brings me back to the first business day of the month however  I want to add something to this that would bring me back to the first business day of the PREVIOUS month when May 1st rolls around- or any new month actually.
So when May 1st comes- and sysdate is may 1st, I want this sql to be able to go back to April 3rd, which is the first business day of April.  The same would apply for June, when June 1st comes around- i want this sql to bring the date back to May 1st which would be the first busness day of that month.
MY end in mind is to create something that I can add to scripts that I have running in oracle that would allow me to schedule them so that I do not have to change the date every new month.

thanks
~jw~

LVL 1
jaw1971Asked:
Who is Participating?
 
RainMan82Commented:
select
(case to_char(trunc(add_months(sysdate,-1),'mm'),'d') when '7' then trunc(add_months(sysdate,-1),'mm')+2 when '1' then trunc(add_months(sysdate,-1),'mm')+1 else trunc(add_months(sysdate,-1),'mm') end) NEWDATE
from dual
0
 
Harish_RajaniCommented:
Use the add month function

Try
select trunc( add_months(sysdate, -1), 'MM') from dual.

This will give you the idea..

Then replace all sysdates in your query with addmonths(sysdate, -1).

Rgds,
HR
0
 
jaw1971Author Commented:
Rainman82
thanks- this is what I wanted
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.

All Courses

From novice to tech pro — start learning today.