SEARCH


 


Find Exact Difference between dates

If you need to find the exact difference between two dates worked out to the number of years and the number of days as separate columns then try the following SQL:

SELECT DOB, DOD, ABS(years) years,
GREATEST(DOB,DOD) - ADD_MONTHS(LEAST(DOB,DOD),ABS(12*years)) days
FROM
(
SELECT DOB,DOD, TRUNC(MONTHS_BETWEEN(DOB,DOD) years
FROM <tablename>
)