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

165
Vistas
how to subtract db time from real time

I have this:

let minute = timeSplit[0];
let today = new Date();
if (Math.abs(today.getMinutes() - Number(minute)) <= 5) {
  client.messages.create(
    {
      to: userPhoneNumber,
      from: "12055578708",
      body:
        "hello " +
        userNameString +
        ", \nYour training session just finished with " +
        trainerNameString
    },
    function (err, data) {
      if (err) {
        console.log("err: " + err);
      }
      console.log(data);
    }
  );
} else {
  console.log("not working");
}

what it does is gets the current minute (ex. 54th minute of the hour), and subtract it from the minute that is in my database. If my db minute is within 5 minutes of the current minute, then do the next part.

However, in my db is both minute and hour. i need to check if the time in my db is within 5 minutes of the current time. minute and hour are both just string values. How can i do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have the hour and the minute and you need to check whether that is within 5 minutes of the current time.

What you can do is build a date object for the same day, but using the time you have stored. So, if you have your minute and hour you want to compare, then you can do this:

const today = new Date();
const myTime = new Date(today.getFullYear(), today.getMonth(), today.getDay(), hour, minute);

Now you have two date objects that you can compare. When you subtract one from the other, the result will be in milliseconds, so you need to do some work to convert that to minutes. In this case we divide by 1000 to get seconds and then divide by 60 to get minutes. Then you apply the absolute function and check if it is less than 5.

const difference = Math.abs((today - myTime) / 1000 / 60);
if (difference <= 5) {
  // send message
} else {
  // don't send the message now
}
about 4 years ago · Juan Pablo Isaza 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