Search This Blog

Tuesday, 4 August 2015

Oracle Query to Calculate Age (Years, Months, Days)

SELECT
TRUNC(MONTHS_BETWEEN(SYSDATE,DOB)/12) YEAR,

 TRUNC(MOD(MONTHS_BETWEEN(SYSDATE,DOB),12)) MONTH,

 TRUNC(SYSDATE-ADD_MONTHS(DOB,TRUNC(MONTHS_BETWEEN(SYSDATE,DOB)/12)*12+TRUNC(MOD(MONTHS_BETWEEN(SYSDATE,DOB),12)))) DAY

FROM (SELECT TO_DATE('01071981','DDMMYYYY') DOB FROM DUAL);

No comments:

Post a Comment