Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Subtração de Data Oracle


Usar:
SELECT TO_CHAR(date1,'MMDDYYYY:HH24:MI:SS') date1,
       TO_CHAR(date2,'MMDDYYYY:HH24:MI:SS') date2,
       TRUNC(86400*(date2-date1)) - 60*(TRUNC((86400*(date2-date1))/60)) seconds,
       TRUNC((86400*(date2-date1))/60) - 60*(TRUNC(((86400*(date2-date1))/60)/60)) minutes,
       TRUNC(((86400*(date2-date1))/60)/60) - 24*(TRUNC((((86400*(date2-date1))/60)/60)/24)) hours,
       TRUNC((((86400*(date2-date1))/60)/60)/24) days,
       TRUNC(((((86400*(date2-date1))/60)/60)/24)/7) weeks
  FROM TABLE

Referência:Uma comparação dos tipos de dados DATE e TIMESTAMP da Oracle