天,小時,分鐘,秒差異。例如 - 複製/粘貼以查看輸出。與您的日期更換日期...:只有
SELECT start_date, end_date, time_diff,
EXTRACT(DAY FROM time_diff) days,
EXTRACT(HOUR FROM time_diff) hours,
EXTRACT(MINUTE FROM time_diff) minutes,
EXTRACT(SECOND FROM time_diff) seconds
FROM
(
Select start_date, end_date, (end_date - start_date) time_diff
From
(
Select CAST(to_date('01/01/2012 10:00:00 am', 'dd/mm/yyyy hh:mi:ss am') AS TIMESTAMP) end_date
, CAST(to_date('01/01/2012 07:00:00 am', 'dd/mm/yyyy hh:mi:ss am') AS TIMESTAMP) start_date
From dual
)
)
/
減去時間例如:
SELECT trunc(mydate/3600) hr
, trunc(mod(mydate, 3600)/60) mnt
, trunc(mod(mydate, 3600)/60 /60) sec
FROM
(
SELECT (to_date('01/03/2012 10:00:00', 'mm/dd/yyyy hh24:mi:ss') -
to_date('01/01/2012 07:00:00', 'mm/dd/yyyy hh24:mi:ss')) * 86400 mydate
FROM dual
)
/
HR MNT SEC
-------------
51 0 0
來源
2013-04-02 13:15:10
Art
「*,但扔了一個錯誤*」:和錯誤是什麼? –