On 12/5/24 20:39, Daniele Varrazzo wrote:
<snip>
Adrian has already provided a few workarounds for the problem you
report - thank you very much!. The one I prefer is however the
following, because it does without string operations: it makes use of
the possibility to multiply an interval by a scalar:

     >>> cur.execute("select now(), now() + %s * '1 second'::interval",
(10,)).fetchone()
     (datetime.datetime(2024, 12, 6, 2, 33, 32, 117134,
tzinfo=zoneinfo.ZoneInfo(key='Europe/London')),
      datetime.datetime(2024, 12, 6, 2, 33, 42, 117134,
tzinfo=zoneinfo.ZoneInfo(key='Europe/London')))

Oh I hadn't even thought about multiplying an interval, that's a very clean approach. Prior to e-mailing the list I'd tried something similar to (but not as thorough as) Adrian's suggestion and it had failed, but if it works I like the look of this.

I vaguely recall having a similar interval manipulation headache in a PHP portion of this project, I shall try the same thing there.

Thank you so much!

Daniel Johnson
djohn...@progman.us



Reply via email to