Oracle 时间相减

--天
select (sysdate - to_date('2012-08-27 16:03:00', 'yyyy-mm-dd hh24:mi:ss'))
  from dual;
--时  
select (sysdate - to_date('2012-08-27 16:03:00', 'yyyy-mm-dd hh24:mi:ss')) * 24
  from dual;
--分
select (sysdate - to_date('2012-08-27 16:03:00', 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60
  from dual;
--秒
select (sysdate - to_date('2012-08-27 16:03:00', 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60 * 60
  from dual;

--天
select (to_date('2012-08-27 17:10:00', 'yyyy-MM-dd HH24:MI:SS') -
       to_date('2012-08-26 17:10:00', 'yyyy-MM-dd HH24:MI:SS'))
  from dual;
--结果:1天
  
--时  
select (to_date('2012-08-27 17:10:00', 'yyyy-MM-dd HH24:MI:SS') -
       to_date('2012-08-26 17:10:00', 'yyyy-MM-dd HH24:MI:SS')) * 24
  from dual;
--结果:24小时

--分
select (to_date('2012-08-27 17:10:00', 'yyyy-MM-dd HH24:MI:SS') -
       to_date('2012-08-26 17:10:00', 'yyyy-MM-dd HH24:MI:SS')) * 24 * 60
  from dual;
--结果:1440分

--秒
select (to_date('2012-08-27 17:10:00', 'yyyy-MM-dd HH24:MI:SS') -
       to_date('2012-08-26 17:10:00', 'yyyy-MM-dd HH24:MI:SS')) * 24 * 60 * 60
  from dual;
--结果:86400秒


--oracle 两个时间相减默认的是天数

--oracle 两个时间相减*24 相差的为小时数

--oracle 两个时间相减*24*60 相差的为分钟数

--oracle 两个时间相减*24*60*60 相差的为秒数



你可能感兴趣的:(oracle,Date)