SQL - two months from todays date in Oracle

前端 未结 4 797
暖寄归人
暖寄归人 2021-01-18 18:23

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.

I know I need to use SYS

4条回答
  •  有刺的猬
    2021-01-18 18:45

    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.

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

提交回复
热议问题