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

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


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

SELECT date_field + interval '1 hour' * start_time

start_time can be any numerical value.
'1 hour' can be shortened to '1h'.
interval can be multiplied a scalar.


Found the answer, in another SO question:

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

Hope that helps anyone


The one worked for me is

SELECT date_field + interval '1' HOUR * start_time

start_time can be any numerical value.