Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda