AJM
AJM

Reputation: 32490

SQL - two months from todays date in Oracle

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 SYSDATE but am not familiar with date stuff in Oracle so am unsure as to the rest.

Upvotes: 6

Views: 50220

Answers (4)

Prince Thomas
Prince Thomas

Reputation: 31

Here is a query that will give the last 2 month data based on the current date.

SELECT * FROM tableName WHERE created_on >= add_months(sysdate, -2);

Upvotes: 3

densom
densom

Reputation: 735

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)

Upvotes: 0

Mercer Traieste
Mercer Traieste

Reputation: 4678

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

Upvotes: 18

RRUZ
RRUZ

Reputation: 136431

try this

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

Bye

Upvotes: 1

Related Questions