简体   繁体   中英

How to use Oracle SQL Date and Time

I have the following example :

select * from my_table
where date between ('19-06-2014 00:00:00,000000000 EUROPE/BUCHAREST') and ('19-06-2014 23:59:59,000000000 EUROPE/BUCHAREST'

If I run this query it returns the correct values . What I need is something like this :

select * from my_table
where date between ('today - 2DAYS ') and ('today - 1DAY')

Do you have any idea how I can achieve this?

Try following solution:

--for one day results

select * from my_table where date between sysdate - 2  and sysdate - 1 

--If you wish to start from the beginning of the day:

select * from my_table where date between trunc(sysdate) - 2  and trunc(sysdate) - 1 

FYI - sysdate referes the current date and substrating value will be counted in terms of day. If you wish to substract 12 hrs, you should substract 0.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM