How to subtract hours from a date in Oracle so it affects the day also

前端 未结 5 1976
暗喜
暗喜 2021-02-01 17:23

I\'m trying to subtract date from Oracle so it even effect the day as well. For example, if the timestamp is 01/June/2015 00 hours and if I subtract 2 hours, I want to be able

5条回答
  •  野性不改
    2021-02-01 18:19

    Try this:

    SELECT to_char(sysdate - (2 / 24), 'MM-DD-YYYY HH24') FROM DUAL
    

    To test it using a new date instance:

    SELECT to_char(TO_DATE('11/06/2015 00:00','dd/mm/yyyy HH24:MI') - (2 / 24), 'MM-DD-YYYY HH24:MI') FROM DUAL
    

    Output is: 06-10-2015 22:00, which is the previous day.

提交回复
热议问题