From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: timestamp - timestamp result
Date: Fri, 26 Jun 2020 07:28:43 +0200
Message-ID: <c1696f68-fa8d-7759-6a9c-eb293ab1bbc9@gmx.net> (raw)
I regularly see people suggesting to use
extract(day from one_timestamp - other_timestamp)
to calculate the difference between two timestamps in days.
But I wonder if the "format" of the resulting interval is guaranteed to only have days
(and not months or years)
The following:
timestamp '2020-06-26 17:00:00' - timestamp '2019-04-01 14:00:00'
returns an interval like this:
0 years 0 mons 452 days 3 hours 0 mins 0.0 secs
However, is there ever a chance that the expression will yield the (equivalent) interval:
1 years 2 mons 25 days 3 hours 0 mins 0.0 secs
e.g. as the age() function does.
Is it safe to assume that "timestamp - timestamp" will never contain units larger then days?
Thomas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: shammat@gmx.net
Subject: Re: timestamp - timestamp result
In-Reply-To: <c1696f68-fa8d-7759-6a9c-eb293ab1bbc9@gmx.net>
References: <c1696f68-fa8d-7759-6a9c-eb293ab1bbc9@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox