Why is the Oracle Months_Between function not accurate and how can I make an accurate version in SQL Server?

Viewed 28

I am in the middle of converting over an application from Oracle to SQL Server. The application uses a lot of stored procedures and functions. While converting one of the packages from Oracle, I came across this function called Months_Between(). I performed some testing and realized that the function is not accurate. I also found other stack overflow questions with the same issue.

For instance, calculating a single day using Months_Between(2020-02-01, 2020-02-01) will return 0.000. Changing that to Months_Between(2020-02-01, 2020-02-02) will return 0.0322580645; which is equal to 1/31.

What can you use in SQL Server to get an accurate calculation of Months_Between; just a positive value? Bonus question, what would you use to mimic the exact results of the Months_Between function; positives and negatives?

0 Answers
Related