Oracle: how to add minutes to a timestamp?

前端 未结 13 1293
盖世英雄少女心
盖世英雄少女心 2020-11-30 02:37

I need to add 30 minutes to values in a Oracle date column. I do this in my SELECT statement by specifying

to_char(date_and_time + (.000694 * 31)

13条回答
  •  甜味超标
    2020-11-30 02:49

    I prefer using an interval literal for this, because interval '30' minute or interval '5' second is a lot easier to read then 30 / (24 * 60) or 5 / (24 * 60 * 69)

    e.g.

    • some_date + interval '2' hour
    • some_date + interval '30' minute
    • some_date + interval '5' second
    • some_date + interval '2' day

    You can also combine several units into one expression:

    • some_date + interval '2 3:06' day to minute

    Adds 2 days, 3 hours and 6 minutes to the date value

    The above is also standard SQL and also works in several other DBMS.

    More details in the manual: https://docs.oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00221

提交回复
热议问题