Re: How to add a variable to a timestamp.

From: Erik Wienhold <ewie(at)ewie(dot)name>
To: Eagna <eagna(at)protonmail(dot)com>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to add a variable to a timestamp.
Date: 2022-10-29 18:35:30
Message-ID: 629544703.694927.1667068530445@office.mailbox.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On 29/10/2022 19:35 CEST Eagna <eagna(at)protonmail(dot)com> wrote:
>
> I'm trying to do something like this.
>
> SELECT
> d.i,
> h.i,
>
> '2022-10-31 00:00:00'::TIMESTAMP + INTERVAL 'd.i DAY'
> FROM
> GENERATE_SERIES(0, 6) AS d(i),
> GENERATE_SERIES(0, 23) AS h(i);
>
> where I add d.i days (and also h.i hours) to a timestamp.
>
> I can't seem to get this to work. Any ideas appreciated.

Create the interval with make_interval(days => d.i, hours => h.i).

https://www.postgresql.org/docs/15/functions-datetime.html#id-1.5.8.15.6.2.2.28.1.1.1

--
Erik

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2022-10-29 20:10:24 Re: How to add a variable to a timestamp.
Previous Message Eagna 2022-10-29 17:35:22 How to add a variable to a timestamp.