user3206440
user3206440

Reputation: 5049

formatting timestamp to 1/100s / 1/10s of seconds

In PostgreSQL I could do the formatting of a timestamp to seconds as follows.

to_timestamp('2017-02-20 08:22:44.166', 'YYYY-MM-DD HH24:MI:SS') --> 2017-02-20 08:22:44

I need to format the above time stamp into 100s and 10s of seconds.

--> 2017-02-20 08:22:44.17 (formatted to 1/100s of second)

--> 2017-02-20 08:22:44.2 (formatted to 1/10 th of second)

Upvotes: 1

Views: 79

Answers (1)

klin
klin

Reputation: 121594

Cast a value to timestamp with a specified precision:

select '2017-02-20 08:22:44.166'::timestamp(2), '2017-02-20 08:22:44.166'::timestamp(1)

       timestamp        |       timestamp       
------------------------+-----------------------
 2017-02-20 08:22:44.17 | 2017-02-20 08:22:44.2
(1 row)

Upvotes: 2

Related Questions