Oracle 日期计算 trunc(sysdate)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12064312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:04:02  来源:igfitidea点击:

Oracle date calculations trunc(sysdate)

oracledatetimetruncatedate-arithmetic

提问by rgvwed

I need to qualify a query from a Database on Oracle for a report based on certain date ranges

我需要根据特定日期范围限定来自 Oracle 数据库的查询以获得报告

1st query

第一个查询

5pm-7am (Between 5pm yesterday and Today 7am)

下午 5 点至早上 7 点(昨天下午 5 点到今天早上 7 点之间)

2nd query

第二次查询

for 7am-5pm ((Between 5pm yesterday , Today 7am)

7am-5pm((昨天下午5点,今天早上7点)

How would I do this??? I need to know Oracle Syntax to specify those date criterias

我该怎么做???我需要知道 Oracle 语法来指定这些日期标准

Thanks in Advance

提前致谢

回答by Justin Cave

I would probably do something like

我可能会做类似的事情

WHERE some_date_col BETWEEN trunc(sysdate-1) + interval '17' hour -- 5pm yesterday
                        AND trunc(sysdate) + interval '7' hour -- 7am today

and

WHERE some_date_col BETWEEN trunc(sysdate) + interval '7' hour -- 7am today
                        AND trunc(sysdate) + interval '17' hour -- 5pm today

There is another thread on adding hours and minutes to datesthat goes into more detail about different ways of specifying date offsets.

还有另一个关于向日期添加小时和分钟的主题,其中详细介绍了指定日期偏移的不同方法。