0
votes

I would like to convert timestamp with UTC to milliseconds in Postgres. I am using this query on Ruby console (using Postgres). My query :

u.tasks.group("date","id").pluck("EXTRACT(EPOCH FROM date)*1000","id")

Above query results,

Thu, 05 Jul 2018 05:05:39 UTC +00:00 to 1530767139732.35

Output looks good but after '.' i don't need 35. Is there any way to get 13 digit milliseconds as output.

I would appreciate the help.

1
@a_horse_with_no_name I have updated my question. I am using Ruby console and Postgres. - TEMP

1 Answers

0
votes

You can use trunc() function from postgresql.

The following sql will truncate the digits after decimal and return only bigint number.

For example,

select trunc(extract(epoch from now() )*1000);

will return me, 1538633517552.

where as without trunc(), it will return 1538633517552.41