In Oracle/PLSQL, the months_between function returns the number of months between date1 and date2.
Syntax
The syntax for the months_between function is:
months_between( date1, date2 )
【Oracle|Oracle/PLSQL: Months_Between Function】date1 and date2 are the dates used to calculate the number of months.
If a fractional month is calculated, the months_between function calculates the fraction based on a 31-day month.
Applies To
- Oracle 11g, Oracle 10g, Oracle 9i, Oracle 8i
months_between (to_date ('2003/01/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd') )
would return -2.41935483870968
Example #2
months_between (to_date ('2003/07/01', 'yyyy/mm/dd'), to_date ('2003/03/14', 'yyyy/mm/dd') )
would return 3.58064516129032
Example #3
months_between (to_date ('2003/07/02', 'yyyy/mm/dd'), to_date ('2003/07/02', 'yyyy/mm/dd') )
would return 0
Example #4
months_between (to_date ('2003/08/02', 'yyyy/mm/dd'), to_date ('2003/06/02', 'yyyy/mm/dd') )
would return 2
推荐阅读
- Oracle RAC模式下如何部署NTP
- ORACLE|How to create new user for ORACLE 19c (CDB & PDB)
- ORACLE|How to install oracle19c in Centos8
- mysql|MySQL存储引擎
- Jmeter操作oracle简单示例
- ORACLE 12的ORA-01033问题操作过程
- Jmeter操作oracle
- oracle拨云见日第8篇之Oracle11.2.0.1.0升级11.2.0.4.3
- oracle拨云见日第7篇之Oracle10.2.0.1升级10.2.0.5.19