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

190
Views
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
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!