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

294
Vistas
javascript getHours & getMinutes - myHours & myMinutes

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 get the current minute (ex. 45th minute of the hour), and subtracts 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 I have both minute and hour stored. i need to check if the time in my db is within 5 minutes of the current time, including the hour. minute and hour are both just string values in my db. How can i do this?

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

0

The UNIX timestamp is the number of seconds since January 1st, 1970. By using the current timestamp and subtracting it from one in the future or one in the past you receive a difference in seconds. From my understanding this is exactly what you need for your project. Code like this is what I imagine will be what you're aiming for:

/* JavaScript returns miliseconds so 
    we divide and round down to get seconds */
let now = Math.floor(Date.now() / 1000); 

if(now <= (5 * 60)) { // Convert 5 minutes to 300 seconds
    // Send your message
} else {
    // Don't send message
}
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