Thursday, 15 May 2014

How to get number of years, months, days between two dates

SELECT    TRUNC (MONTHS_BETWEEN (:end_date, :start_date) / 12)
       || ' YEARS '
       || MOD (TRUNC (MONTHS_BETWEEN (:end_date, :start_date)), 12)
       || ' MONTHS '
       || (  TO_DATE (:end_date)
           - ADD_MONTHS (:start_date,
                         TRUNC (MONTHS_BETWEEN (:end_date, :start_date))
                        )
          )
       || ' DAYS'
  FROM DUAL;

No comments:

Post a Comment