DATEADD equivalent in PostgreSQL

Is there an equivalent to this T-SQL command in PostgreSQL?

select dateadd(hh,duration_in_hours,start_date) as end_date

      

I found an interval keyword followed by a line, but this terrible construct returns a syntax error:

select start_date + interval cast(duration_in_hours as varchar) || ' hours'

      

It only allows the string constant after the "interval" keyword. I'm sure there must be some similar function in pgsql, but I can't find it.

+3


source to share


2 answers


You can do it like this:

select start_date + (duration_in_hours * interval '1 hour') from your_table

      



See SQL Fiddle Sample

+9


source


Postgres has no function date_add

or any equivalent - the way to manipulate dates is to use the +

value operator interval

, as you mentioned.



0


source







All Articles