Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
Postgres truncate the millisecond part from three to two digits

I am formatting an input that I get in Timestamp datatype and sending the output as a text in the below format

2020-07-30 10:45:23.638 PM

For this I'm using the below query

select to_char(input_timestamp, 'YYYY-MM-DD HH:MI:SS.MS AM');

But I want the microsecond part truncated to 2 digits instead of 3 digits. The output will be in TEXT datatype. Expecting help on this.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try this:

select 
    left(to_char(input_timestamp::timestamp(2), 'YYYY-MM-DD HH:MI:SS.MS'), 22) || 
    to_char(input_timestamp, 'FM AM');

First round to two microsecond' digits, convert to string, chop to 22 characters and then concatenate the meridiem indicator.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!