MONTHS_BETWEEN 获取两个日期之间的月份数


Syntax

Description of months_between.gif follows

Purpose

MONTHS_BETWEEN returns number of months between dates date1 and date2. The month and the last day of the month are defined by the parameter NLS_CALENDAR. 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.

 

SQL> select months_between(add_months(sysdate, 5), sysdate) as "months" from dual
  2  /

    months
----------
         5

SQL> select months_between(sysdate, add_months(sysdate, 9)) as "months" from dual
  2  /

    months
----------
        -9

 

SQL> select months_between(sysdate+20, sysdate) as "months" from dual
  2  /

    months
----------
 .64516129

SQL> select months_between(sysdate, sysdate+31) as "months" from dual
  2  /

    months
----------
-1.0322581

SQL> select months_between(sysdate+30, sysdate) as "months" from dual
  2  /

    months
----------
         1

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM