默认情况下,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秒
来源:http://www.blogjava.net/pure/archive/2007/10/18/153914.html