anvd anvd - 8 months ago 95
Python Question

Convert ts field to seconds

I need to convert the ts field to a

floating point number expressed in seconds


| ts | user_id | object_id |
+-------------------------------+---------+-------------+
| 2016-08-12 15:13:34.898779+01 | 12 | 5 |


The same format that can be achieved with

import time
ts = time.time()
print ts #1507023571.12


So, my question is How can I convert the ts field?

Answer Source

use epoch:

t=# select extract(epoch from now()), now();
    date_part     |              now
------------------+-------------------------------
 1507024254.74876 | 2017-10-03 09:50:54.748764+00
(1 row)

edit

use smth like: select extract(epoch from ts) ts from reputation_log

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download