时间:2021-07-01 10:21:17 帮助过:52人阅读
1,比较当前时间与指定时间相差分钟数: select sysdate, sysdate - to_date(
1,比较当前时间与指定时间相差分钟数:
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,to_date('2009-2-20 17:45:39','yyyy-mm-dd hh24:mi:ss'),
ROUND(TO_NUMBER(sysdate - to_date('2009-2-20 17:45:39','yyyy-mm-dd hh24:mi:ss')) * 24 * 60)
from dual;
输出结果:2009-2-20 17:36:14 2009-2-20 17:45:39 -9
2,同理,可比较相差天数、小时数、秒数等,只需根据需要替换下面的参数:
两个Date类型字段:START_DATE,END_DATE,,计算这两个日期的时间差(分别以天,小时,分钟,秒,毫秒):
天:
ROUND(TO_NUMBER(END_DATE - START_DATE))
小时:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24)
分钟:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60)
秒:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60)
毫秒:
ROUND(TO_NUMBER(END_DATE - START_DATE) * 24 * 60 * 60 * 1000)
3,格式输出
select extract(DAY from interval)||'天'||extract(HOUR from interval)||'小时'||extract(MINUTE from interval)||'分钟'||extract(SECOND from interval)||'秒' 间隔 from (
select numtodsinterval(to_date('2008-10-09 12:30:18','yyyy-mm-dd hh24:mi:ss
')-to_date('2008-10-28','yyyy-mm-dd'),'DAY') interval from dual
)
输出:-18天-11小时-29分钟-41.999999999秒