How can I get the difference in hours between two dates?

后端 未结 4 1925
情歌与酒
情歌与酒 2020-12-10 18:43

I have to do a \"select\" that returns the difference between a field of type date from the database and the current date in hours. How can I do this in oracle?

I tr

4条回答
  •  离开以前
    2020-12-10 19:29

    Diference between two dates in hours and minutes

    SELECT     TRUNC(minutes_ / 60) || ' Hours, ' || TRUNC(MOD(minutes_,  60)) || ' Minutes'  diference
    FROM     ( SELECT  (sysdate - to_date('16/10/2019 18:45:00', 'DD/MM/YYYY HH24:MI:SS')) * 24 * 60     AS minutes_
      FROM     dual
    );
    

    Diference between two dates in hours

    SELECT     ROUND(minutes_ / 60, 2) || ' Hours ' 
    FROM     ( SELECT  (sysdate - to_date('16/10/2019 18:45:00', 'DD/MM/YYYY HH24:MI:SS')) * 24 * 60     AS minutes_
      FROM     dual
    );
    

    Diference between two dates in hours (truncate)

    SELECT     ROUND(minutes_ / 60, 2) || ' Hours ' 
    FROM     ( SELECT  (sysdate - to_date('16/10/2019 18:45:00', 'DD/MM/YYYY HH24:MI:SS')) * 24 * 60     AS minutes_
      FROM     dual
    );
    

提交回复
热议问题