Hi all,
I would like to know the fastest (months_between, to_number, etc) way to compute the difference in years between two date fields.
Any help will be appreciated.
You definitely shouldn't calculate days and then divide by 365, or even 365.25. That calculation will sometimes be wrong because of leap years.
I think you answered your own question. I don't see any reason not to use the months_between function and then divide by 12. You can also truncate the result if you want to express age in the usual way - an exact integer that doesn't change until your next birthday.
select select trunc(months_between(sysdate,birthdate)/12) from test;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.