Thursday, May 17, 2012

Get date diff in Year, Months, and Days in oracle

with t as (select to_date('30-JAN-1995') as date1
                     ,sysdate as date2 from dual)
                    
    select
      trunc((date2-date1)/365) as Years,
      trunc((trunc(date2-date1) - trunc((date2-date1)/365) * 365)/30) as Months,
      trunc((date2-date1) - ((trunc((trunc(date2-date1) - trunc((date2-date1)/365) * 365)/30) *30 ) + (trunc((date2-date1)/365) * 365))) days
   from t

No comments:

Post a Comment