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

191
Vistas
NodeJS calculating difference between timestamps based on specific conditions

Have an interesting problem.

I have a SQL database, 50000+ entries containing data that looks as follows when queried with KnexJS:

[{
    id: 65532,
    status: 0.00,
    timestamp: 1656124205000,
  },
{
    id: 65533,
    status: 49.81,
    timestamp: 1656124503000,
  },
{
    id: 65534,
    status: 0.00,
    timestamp: 1656124909000,
  }
.... 60000+ more entries
]

I'm using Knex as the query builder.

I want be able to find every object where status is 0 and then get the following object where status is not 0 and then calculate the time difference for each occurrence where that happened.

Usually 0.00 won't be consecutive, but there's no guarantee for that, else I would've just grabbed the id/index where status is 0.00 and + 1.

Any suggestions where to get started with this kinda logic?

about 4 years ago · Juan Pablo Isaza
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