Re: convert time format retuned by a select query

From: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
To: Johan Martinez <jmartiee(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>, pgsql-novice-owner(at)postgresql(dot)org
Subject: Re: convert time format retuned by a select query
Date: 2011-12-09 03:42:07
Message-ID: OF124301AD.4719D8B7-ON65257961.00143972-65257961.00145567@ibsplc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hello,
>
> I would like to subtract two columns - create_time and update_time
> of 'timestamp without time zone' type and then order results based
> on subtraction-result (time interval). I checked http://
> www.postgresql.org/docs/current/static/functions-datetime.html ,
> however these examples didn't work with actual column values.
> e.g.something like:
> 'select epoch (update_time) - epoch (create_time) AS Column1 from
> users order by Column1; '
Will this do?
test=# select update_time, create_time, update_time-create_time as diff
from myt
order by update_time-create_time desc;
update_time | create_time | diff
-------------------------+-------------------------+-----------------
2011-12-12 00:09:28.852 | 2011-12-09 09:09:28.852 | 2 days 15:00:00
2011-12-11 19:09:22.619 | 2011-12-09 09:09:22.619 | 2 days 10:00:00
2011-12-11 09:09:15.744 | 2011-12-09 09:09:15.744 | 2 days
2011-12-10 09:09:10.104 | 2011-12-09 09:09:10.104 | 1 day
(4 rows)

Regards,
Jayadevan

DISCLAIMER:

"The information in this e-mail and any attachment is intended only for
the person to whom it is addressed and may contain confidential and/or
privileged material. If you have received this e-mail in error, kindly
contact the sender and destroy all copies of the original communication.
IBS makes no warranty, express or implied, nor guarantees the accuracy,
adequacy or completeness of the information contained in this email or any
attachment and is not liable for any errors, defects, omissions, viruses
or for resultant loss or damage, if any, direct or indirect."

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jean-Yves F. Barbier 2011-12-09 05:35:42 Re: pgAdmin3 grant wizard question
Previous Message Michael Rowan 2011-12-08 22:53:31 pgAdmin3 grant wizard question