?
Solved

Oracle - Date SQL calcs

Posted on 2011-02-21
4
Medium Priority
?
333 Views
Last Modified: 2012-08-14
Looking for a "between" statement that will go back 30 days from yesterday's date and end at yesterday's date.

Example if the statement ran today:
...where full_date between ('1/21/2011' and '2/20/11')



0
Comment
Question by:carsRST
  • 3
4 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 34943988
where full_date between trunc(sysdate)-31 and trunc(sysdate)-1


if you want to include all time of yesterday then you'll have to include the
time piece in the between

where full_date between trunc(sysdate)-31 and trunc(sysdate)-1 + (86399/86400)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 34944010
or use >=  <=


where full_date >=trunc(sysdate)-31 and
full_date <= trunc(sysdate)-1 + (86399/86400)

or

where full_date >=trunc(sysdate)-31 and
full_date <= trunc(sysdate)  - (1/86400)

or



where full_date >=trunc(sysdate)-31 and
full_date < trunc(sysdate)     -----  note <  not <=


0
 
LVL 16

Author Closing Comment

by:carsRST
ID: 34944019
sdstuber = great person

Thanks!
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 34944027
and finally, one more option...


where full_date between trunc(sysdate)-31 and trunc(sysdate)- (1/86400)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question