How to add a variable number of hours to a date in PostgreSQL?

前端 未结 4 645
攒了一身酷
攒了一身酷 2020-12-29 18:46

Apparently, PostgreSQL doesn\'t have DATEADD, because you can just use the + or - operators.

I need to add a number of hours t

相关标签:
4条回答
  • 2020-12-29 18:50

    Found the answer, in another SO question:

    date + interval '1' minute * FLOOR(start_time * 60)
    

    Hope that helps anyone

    0 讨论(0)
  • 2020-12-29 18:53

    If anyone wants to add in time stamp then

    select time '05:00' - interval '2 hours'    
    
    0 讨论(0)
  • 2020-12-29 19:02

    The one worked for me is

    SELECT date_field + interval '1' HOUR * start_time
    

    start_time can be any numerical value.

    0 讨论(0)
  • 2020-12-29 19:09

    Since you want to add hours, it should rather be:

    SELECT date_field + interval '1h' * start_time
    

    start_time can be any numerical value.

    0 讨论(0)
提交回复
热议问题