In Oracle, is there a function that calculates the difference between two Dates?

后端 未结 5 845
长情又很酷
长情又很酷 2020-12-18 16:16

In Oracle, is there a function that calculates the difference between two Dates? If not, is a way to display the difference between two dates in hours and minutes?

5条回答
  •  执笔经年
    2020-12-18 17:03

    You can use these functions :

    1) EXTRACT(element FROM temporal_value)

    2) NUMTOYMINTERVAL (n, unit)

    3) NUMTODSINTERVAL (n, unit).

    For example :

    SELECT EXTRACT(DAY FROM NUMTODSINTERVAL(end_time - start_time, 'DAY'))
       || ' days ' || 
       EXTRACT(HOUR FROM NUMTODSINTERVAL(end_time - start_time, 'DAY'))
       ||':'|| 
       EXTRACT(MINUTE FROM NUMTODSINTERVAL(end_time - start_time, 'DAY')) 
       ||':'||
       EXTRACT(SECOND FROM NUMTODSINTERVAL(end_time - start_time, 'DAY')) 
       "Lead Time"
    FROM table;
    

提交回复
热议问题