Oracle: how to add minutes to a timestamp?

前端 未结 13 1213
盖世英雄少女心
盖世英雄少女心 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:55

    Be sure that Oracle understands that the starting time is PM, and to specify the HH24 format mask for the final output.

    SELECT to_char((to_date('12:40 PM', 'HH:MI AM') + (1/24/60) * 30), 'HH24:MI') as time
      FROM dual
    
    TIME
    ---------
    13:10
    

    Note: the 'AM' in the HH:MI is just the placeholder for the AM/PM meridian indicator. Could be also 'PM'

    0 讨论(0)
  • 2020-11-30 02:58

    To edit Date in oracle you can try

      select to_char(<columnName> + 5 / 24 + 30 / (24 * 60),
               'DD/MM/RRRR hh:mi AM') AS <logicalName> from <tableName>
    
    0 讨论(0)
  • 2020-11-30 03:01

    If the data type of the field is date or timestamp, Oracle should always give the correct result if you add the correct number given in number of days (or a the correct fraction of a day in your case). So if you are trying to bump the value in 30 minutes, you should use :

    select field + 0.5/24 from table;
    

    Based on the information you provided, I believe this is what you tried to do and I am quite sure it works.

    0 讨论(0)
  • 2020-11-30 03:03

    Can we not use this

    SELECT date_and_time + INTERVAL '20:00' MINUTE TO SECOND FROM dual;
    

    I am new to this domain.

    0 讨论(0)
  • 2020-11-30 03:03
    SELECT to_char(sysdate + (1/24/60) * 30, 'dd/mm/yy HH24:MI am') from dual;
    

    simply you can use this with various date format....

    0 讨论(0)
  • 2020-11-30 03:05

    like that very easily

    i added 10 minutes to system date and always in preference use the Db server functions not custom one .

    select to_char(sysdate + NUMTODSINTERVAL(10,'MINUTE'),'DD/MM/YYYY HH24:MI:SS') from dual;
    
    0 讨论(0)
提交回复
热议问题