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

358
Vistas
postgresql - Format an interval as time with large number of hours

I have an interval that is calculated between events that can be days or hours between them.

Some rows show the desirable

00:15:38.687282

While other give me a worse-to-read

2 days 22:20:33.505085

How can I make the second example return the following?

70:22:33.505085

Thanks for any help.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Another solution:

select extract(epoch from interval '2 days 22:20:33.505085')/3600 * interval '1h';
┌─────────────────┐
│    ?column?     │
╞═════════════════╡
│ 70:20:33.505085 │
└─────────────────┘
(1 row)
over 4 years ago · Santiago Trujillo Denunciar

0

You can build a custom representation with extract():

floor(extract(epoch from val) / 60 / 60)
|| ':' || extract(minute from val)
|| ':' || extract(second from val)

Demo on DB Fiddle:

select 
    floor(extract(epoch from val) / 60 / 60)
    || ':' || extract(minute from val)
    || ':' || extract(second from val) display
from (values ('2 days 22:20:33.505085'::interval)) as t(val)
| display         |
| :-------------- |
| 70:20:33.505085 |
over 4 years ago · Santiago Trujillo Denunciar

0

A quick and dirty solution:

SELECT
   extract(days from '2 days 22:20:33.505085'::interval) * interval '24 hour' + '22:20:33.505085'::interval

 ?column?     
-----------------
 70:20:33.505085

If you want to get more involved then that, account for months, years and so on then you will probably need to build a function.

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