select
EXTRACT(year FROM to_date('2019-09-24 19:38:45','yyyy-mm-dd hh24:mi:ss'))
-EXTRACT(year FROM to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24:mi:ss')) as diff_years,
months_between(to_date('2019-09','yyyy-mm'),to_date('2018-08','yyyy-mm')) as diff_months1,
(EXTRACT(year FROM to_date('2019-09-24 19:38:45','yyyy-mm-dd hh24:mi:ss'))
-EXTRACT(year FROM to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24:mi:ss'))) * 12
+EXTRACT(month FROM to_date('2019-09-24 19:38:45','yyyy-mm-dd hh24:mi:ss'))
-EXTRACT(month FROM to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24:mi:ss')) as diff_months2,
ceil((To_date('2018-09-24 19:38:45','yyyy-mm-dd hh24:mi:ss')-to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24;mi:ss'))) as diff_days,
ceil((To_date('2018-08-23 19:13:01','yyyy-mm-dd hh24-mi-ss')-to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24-mi-ss'))*24) as diff_hours,
ceil((To_date('2018-08-23 19:13:01','yyyy-mm-dd hh24-mi-ss')-to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24-mi-ss'))*24*60) as diff_minutes ,
ceil((To_date('2018-08-23 19:13:01','yyyy-mm-dd hh24-mi-ss')-to_date('2018-08-23 10:13:01','yyyy-mm-dd hh24-mi-ss'))*24*60*60) as diff_seconds
from dual;
计算年数,是通过计算出月数,然后再除以12;(也许会有更好的办法,目前还不知道)在Oracle中,两个日期直接相减,便可以得到天数;计算月数,需要用到months_between函数;
--oracle 求两个日期之间的所有日期
SELECT TO_CHAR((TO_DATE(KSRQ, 'yyyy-MM-dd') + (ROWNUM - 1)), 'yyyy-MM-dd') DT
FROM DUAL
CONNECT BY ROWNUM...
Oracle函数可以实现诸多的功能,下面就介绍使用oracle函数计算时间差的实现方法。两个Date类型字段:START_DATE,END_DATE,计算这两个日期的时间差(分别以天,小时,分钟,秒,毫秒):天: ROUND(TO_NUMBER(END_DATE - START_DATE))小时: ROUND(TO_NUMBER(END_DATE - START_DATE) * 24)分钟: RO...
SELECT TO_CHAR(TO_DATE('2020-02-01', 'YYYY-MM-DD') + ROWNUM - 1, 'YYYY-MM-DD') DAY_ID
FROM DUAL
CONNECT BY ROWNUM < TO_DATE('2020-04-01', 'YYYY-MM-DD') - TO_DATE('2020-02-01', 'YYYY-MM-DD') + 1...
SELECT TO_CHAR(ADD_MONTHS(TO_DATE('2018-01', 'YYYY-MM'), ROWNUM - 1),'YYYY-MM') DAY_ID...
Oracle使用日期函数TO_CHAR和TO_DATE来计算两个日期字段之间的天数。可以使用以下SQL语句来计算:SELECT TO_CHAR(TO_DATE('date1','dd-mm-yyyy') - TO_DATE('date2','dd-mm-yyyy')) AS no_of_days FROM dual;
oracle日期查询,oracle怎么查询日期,oracle日期条件怎么查询,oracle TO_CHAR函数,oracle TO_DATE函数,oracle ADD_MONTHS函数,oracle SUBSTR,oracle 字符串截取
oracle查询日期区间