Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Get a Date Range for Previous Month Using SYSDATE

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
I need to create a Date Range using the SYSDATE function for the previous month.

What is the syntax?

Thanks,

Leo ;-)
 
select add_months(trunc(sysdate, 'mm'), -1), trunc(sysdate, 'mm')-1 FROM DUAL
 

Try something like this:

Code:
select ADD_MONTHS(TRUNC(SYSDATE,'MONTH'),-1) + dt
  from (select level dt from dual connect by level < 32)
 Where ADD_MONTHS(TRUNC(SYSDATE,'MONTH'),-1) + dt < TRUNC(SYSDATE,'MONTH')
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

PS: The above is to generate a list of all the days of last month.
Typo fix:
Code:
select ADD_MONTHS(TRUNC(SYSDATE,'MM'),-1) + dt - 1
  from (select level dt from dual connect by level < 32)
 Where ADD_MONTHS(TRUNC(SYSDATE,'MM'),-1) + dt - 1 < TRUNC(SYSDATE,'MM')
/
[bigglasses]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top