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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Month Date Criteria 1

Status
Not open for further replies.

fmrock

Programmer
Sep 5, 2006
510
US
Hey everyone,

I use the following code to pull up accounts that have a date of last week.

Code:
AND tablename.DATEUPDATED between next_day(trunc(sysdate)-13,'SUNDAY') and next_day(trunc(sysdate)-6,'SATURDAY')

I want to do the same thing, but for the last full month. So not matter what day the query is run in Feb 2009, I need to pull accounts with a date of jan 2009
 
FMRock,

There are many good methods to achieve your objective. I like this one:
Code:
AND tablename.DATEUPDATED between add_months(trunc(sysdate,'MM'),-1) and trunc(sysdate,'MM')-(1/24/60/60)...
The code means,
Code:
...between 1 month before midnight on the morning of the beginning of the current month

AND

1 second prior to midnight on the morning of the beginning of the current month.

Let us know how you like this method.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top