oracle獲取年月日,兩個日期相減

2021-10-06 01:37:02 字數 900 閱讀 7813

需求:查詢剩餘多少天?

先看一下我的實際案例:

select ceil(t.mbdcsj - sysdate) as remainingdays from t_zg_mb_mbglb t;
測試案例:

獲取兩時間的相差小時數:

select ceil((to_date('2019-05-02 00:00:00', 'yyyy-mm-dd hh24-mi-ss') -

to_date('2019-04-30 23:59:59', 'yyyy-mm-dd hh24-mi-ss')) * 24) 相差小時數

from dual;

獲取兩時間的相差天數 :

select ceil((to_date('2019-05-02 00:00:00', 'yyyy-mm-dd hh24-mi-ss') -

to_date('2019-04-30 23:59:59', 'yyyy-mm-dd hh24-mi-ss'))) 相差天數

from dual;

獲取兩時間月份差: 

select ( extract(year from to_date('2009-05-01', 'yyyy-mm-dd')) -

extract(year from to_date('2019-04-30', 'yyyy-mm-dd'))

) * 12

+extract(month from to_date('2019-05-01', 'yyyy-mm-dd')) -

extract(month from to_date('2019-04-30', 'yyyy-mm-dd')) months

from dual;

oracle獲取年月日,兩個日期相減

oracle如何計算兩個日期的相差天數 月數 年數 小時數 分鐘數 秒數 1 相差天數 兩個日期相減 oracle中兩個日期相差天數 select to number to date 2018 6 5 yyyy mm dd hh24 mi ss to date 2018 5 31 yyyy mm d...

計算兩個日期相差的年,月,日

計算兩個日期相差的年和月 param fromdate 開始時間 param todate 結束時間 return 想相差年月拼到一起,用逗號隔開,前面為相差年 public static stringbuffer calculator string fromdate,string todate 測...

MySQL計算兩個日期相差的年月日

datediff 結束時間,開始時間 select datediff 2020 06 13 2020 06 12 as diffdate下面這個加了個日期格式化 select datediff 2020 06 13 date format now y m d as diffdatetimestamp...