Thread: convert time format retuned by a select query
'select epoch (update_time) - epoch (create_time) AS Column1 from users order by Column1; '
Any hints or documentation liks will be really nice. Thanks.
jM
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."
>
> 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."