Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - two months from todays date in Oracle

Tags:

sql

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.

like image 475
AJM Avatar asked Aug 12 '09 14:08

AJM


People also ask

How can I calculate months between two dates in Oracle?

MONTHS_BETWEEN returns number of months between dates date1 and date2 . If date1 is later than date2 , then the result is positive. If date1 is earlier than date2 , then the result is negative. If date1 and date2 are either the same days of the month or both last days of months, then the result is always an integer.

How do I calculate months between two dates in SQL?

The MONTHS_BETWEEN() function is used to get the number of months between dates (date1, date2). See the following conditions: If date1 is later than date2, then the result is positive. If date1 is earlier than date2, then the result is negative.

How do you subtract months from Sysdate?

You are in an Oracle forum, so the Oracle answer is: use add_months(sysdate,-2) to subtract two months from the current date. Regards, Rob.

How do you subtract 6 months from current date in SQL?

We can use DATEADD() function like below to Subtract Months from DateTime in Sql Server. DATEADD() functions first parameter value can be month or mm or m, all will return the same result.


3 Answers

 SELECT * from table where date_column >= add_months(TRUNC(SYSDATE) + 1, 2);
like image 80
Mercer Traieste Avatar answered Oct 14 '22 07:10

Mercer Traieste


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);
like image 43
Prince Thomas Avatar answered Oct 14 '22 06:10

Prince Thomas


try this

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

Bye

like image 1
RRUZ Avatar answered Oct 14 '22 07:10

RRUZ