SQL - 在 Oracle 中距今天日期两个月

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1266717/
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-01 03:10:31  来源:igfitidea点击:

SQL - two months from todays date in Oracle

sqloracle

提问by AJM

I have a column that stores the last modified date. I want to check in a SQL query if its value is more than 2 months from the current date.

我有一列存储上次修改日期。如果 SQL 查询的值距当前日期超过 2 个月,我想检查它。

I know I need to use SYSDATE but am not familiar with date stuff in Oracle so am unsure as to the rest.

我知道我需要使用 SYSDATE,但不熟悉 Oracle 中的日期内容,因此我不确定其余部分。

回答by Mercer Traieste

 SELECT * from table where date_column >= add_months(TRUNC(SYSDATE) + 1, 2);

回答by RRUZ

try this

尝试这个

SELECT field1,field2 from yourtable where field_date > add_months(SYSDATE, 2);

Bye

再见

回答by densom

Here is a query WHERE clause that will get you the previous 13 months based on the current date. For example, if today's date is 3/11/2011, the query would return 2/1/2011 through EOD 2/28/2011.

这是一个查询 WHERE 子句,它将根据当前日期获取前 13 个月的信息。例如,如果今天的日期是 3/11/2011,则查询将返回 2/1/2011 到 EOD 2/28/2011。

SELECT * FROM [my-table] WHERE [date-field] BETWEEN TRUNC (ADD_MONTHS (SYSDATE, -13), 'MM') AND TRUNC (LAST_DAY (ADD_MONTHS (SYSDATE, -1))+1)