简体   繁体   English

如何使用Oracle SQL日期和时间

[英]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. 仅供参考-sysdate是指当前日期,替代值将以天为单位。 If you wish to substract 12 hrs, you should substract 0.5. 如果您希望减去12小时,则应减去0.5。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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