Re: Re: Get the difference between two timestamp cells but in a special format in PostgreSQL

From: Colin Lieberman <clieberman(at)turnitin(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: litu16 <litumelendez(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Re: Get the difference between two timestamp cells but in a special format in PostgreSQL
Date: 2015-06-29 15:59:41
Message-ID: CAA-JMUucfGvYarm+XZwD_UeZyJ4vMuZSky7NceoHh2Or4Vks0g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Check the formatting functions documentation:
http://www.postgresql.org/docs/9.4/static/functions-formatting.html

# select to_char( now() - '2015-06-27 14:33:24'
, 'Y"years" MM"months" DD"days" HH:MI:SS"."MS' );

to_char
-------------------------------------
0years 00months 01days 06:24:59.381
(1 row)

On Fri, Jun 26, 2015 at 10:52 AM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 06/25/2015 08:23 PM, litu16 wrote:
>
>> Hi Adrian,
>>
>> but I would like to get the time diff in this format
>>
>> 0years 0months 0days 00:00:00.000
>>
>> not only hours, minutes, seconds.
>>
>> is this possible???
>>
>
> Well age:
>
> http://www.postgresql.org/docs/9.4/interactive/functions-datetime.html
>
> does that sort of:
>
> production=# SELECT age(timestamp '2015-06-26 09:15:15', timestamp
> '2015-06-26 02:16:00');
> age
> ----------
> 06:59:15
> (1 row)
>
> production=# SELECT age(timestamp '2015-06-26 09:15:15', timestamp
> '2015-06-20 02:16:00');
> age
> -----------------
> 6 days 06:59:15
> (1 row)
>
> production=# SELECT age(timestamp '2015-06-26 09:15:15', timestamp
> '2014-06-20 02:16:00');
> age
> ------------------------
> 1 year 6 days 06:59:15
> (1 row)
>
>
>
>
>
>
>> Thanks Advanced.
>>
>>
>>
>> --
>> View this message in context:
>> http://postgresql.nabble.com/Get-the-difference-between-two-timestamp-cells-but-in-a-special-format-in-PostgreSQL-tp5855074p5855215.html
>> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2015-06-29 16:44:34 Re: Which replication is the best for our case ?
Previous Message Holger.Friedrich-Fa-Trivadis 2015-06-29 15:37:36 Re: Which replication is the best for our case ?