Oracle MONTHS_BETWEEN function
How to calculate the number of months between two dates in Oracle?
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.
- 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.
- Otherwise, Oracle Database calculates the fractional portion of the result based on a 31-day month and considers the difference in time components date1 and date2.
|date1||The first date|
|date2||The second date.|
Oracle 12c, Oracle 11g, Oracle 10g, Oracle 9i
Example: Oracle MONTHS_BETWEEN () function
The following statement calculates the months between two specified dates:
SQL> SELECT MONTHS_BETWEEN 2 (TO_DATE('02-02-2015','MM-DD-YYYY'), 3 TO_DATE('12-01-2014','MM-DD-YYYY') ) "Months" 4 FROM DUAL;.
Months ---------- 2.03225806
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join