oracle 時間差計算

2021-06-05 20:17:01 字數 622 閱讀 9130

預設情況下,2個日期相減,得到是乙個數字,需要進一步轉化,以方便識別

select  sysdate,

sysdate - to_date('2007-04-03 13:45:39','yyyy-mm-dd hh24:mi:ss')

from dual

輸出結果:

2007-4-4 am 10:45:56    0.875196759259259

select  sysdate,

trunc(sysdate - to_date('2007-04-03 13:45:39','yyyy-mm-dd hh24:mi:ss'))

||'天'|| to_char(to_date(trunc(((sysdate - to_date('2007-04-03 13:45:39','yyyy-mm-dd hh24:mi:ss'))-trunc(sysdate - to_date('2007-04-03 13:45:39','yyyy-mm-dd hh24:mi:ss')))*86400),'sssss'),

'fmhh24"小時"mi"分鐘"ss"秒"') 

from dual

輸出結果:

2007-4-4 am 10:44:18    0天20小時58分鐘39秒

Oracle計算時間差

oracle中計算時間差是經常用到的。可以使用 日期1 日期2 並加以運算,來獲得你要想的時間差 天 小時 分鐘或者秒。例如 select to date 2012 02 20 17 45 04 yyyy mm dd hh24 mi ss to date 2012 02 19 08 34 04 yy...

Oracle計算時間差

oracle中計算時間差是經常用到的。可以使用 日期1 日期2 並加以運算,來獲得你要想的時間差 天 小時 分鐘或者秒。例如 select to date 2012 02 20 17 45 04 yyyy mm dd hh24 mi ss to date 2012 02 19 08 34 04 yy...

oracle時間差計算

1.months between date1,date2 date1和date2相減得到相差的月份。select months between to date 2015 05 11 yyyy mm dd to date 2015 04 11 yyyy mm dd from dual 相差乙個月。2....