Oracle : how to subtract two dates and get minutes of the result

后端 未结 4 423
粉色の甜心
粉色の甜心 2021-01-04 01:34

I wrote this function to get minutes from a date, but I cannot get minutes between two dates, How to get that ?

FUNCTION get_minute(p_date DATE)
RETURN NUMB         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 01:58

    For those who want to substrat two timestamps (instead of dates), there is a similar solution:

    SELECT ( CAST( date2 AS DATE ) - CAST( date1 AS DATE ) ) * 1440 AS minutesInBetween
    FROM ...
    

    or

    SELECT ( CAST( date2 AS DATE ) - CAST( date1 AS DATE ) ) * 86400 AS secondsInBetween
    FROM ...
    

提交回复
热议问题