大家好,又见面了,我是你们的朋友全栈君。
因系统折旧月份是按当月是否满15天来算是否为一个月,故此研究了下MONTHS_BETWEEN已适应折旧的逻辑
官网函数说明:
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. 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.
MONTHS_BETWEEN返回日期date1和date2之间的月数。如果date1晚于date2,则结果为正数。如果date1早于date2,则结果为负。如果date1和date2是一个月的相同天数或两个月的最后几天,那么结果总是一个整数。否则,Oracle数据库将根据一个31天的月份计算结果的小数部分,并考虑date1和date2时间组件的差异。
examples:
`SELECT MONTHS_BETWEEN (TO_DATE(’02-02-2020′,’MM-DD-YYYY’), TO_DATE(’01-01-2020′,’MM-DD-YYYY’) ) “Months” FROM DUAL;
Months
1.03225806`
months_between算法为01-01-2020到02-02-2020,2020年一月份算一个整月,不整的为2月份的两天,
于是 MONTHS_BETWEEN (TO_DATE(’02-02-2020′,’MM-DD-YYYY’),TO_DATE(’01-01-2020′,’MM-DD-YYYY’) ) = 1 2/31=1.03225806
一般也就是months_between的两个参数月需要计算小数部分,最多为开始月算小数 中间月 结束月;最少为不算,直接为整数月
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/158029.html原文链接:https://javaforall.cn