Oracle - Date SQL calcs

Posted on 2011-02-21
Medium Priority
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')

Question by:carsRST
  • 3
LVL 74

Accepted Solution

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)
LVL 74

Expert Comment

ID: 34944010
or use >=  <=

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


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


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

LVL 16

Author Closing Comment

ID: 34944019
sdstuber = great person

LVL 74

Expert Comment

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

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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…
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 setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

627 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