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

134
Vistas
JS Date incrementation

Doing this without libraries.

dates.forEach((date) => {
  if(date.getDay() == 6) {
    console.log('sat', date)
    var t = new Date()
    console.log('sat new', new Date(t.setDate(date.getDate() + 1)))
  } else ...
}

Gives this output

sat 
Date Sat Jan 01 2022 00:00:00 GMT+0200 (Eastern European Standard Time)
sat new 
Date Sat Apr 02 2022 19:10:27 GMT+0300 (Eastern European Summer Time)

The point of this code is to see if a date is a saturday. If so, increment it towards becoming a work day (i know it says +1 but its a wip)

The result is that the day gets incremented. However for some reason it moves the date towards being in march. I have looked around and apparently this is how you're supposed to do it, but its not doing it.

When I try console.log('sat new', t.setDate(date.getDate() + 1)) (without new Date()) I get a timestamp of 1646236273249. Which this site converts to the 16th of March. Don't know how useful this is.

I hope I gave all the important information here.

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

0

In order to increment a day to a given date:

date = new Date(date)
date.setDate(date.getDate() + 1)
console.log(date)
about 4 years ago · Juan Pablo Isaza Denunciar

0

var t = new Date() - not passing anything to the Date constructor will make it "right now". I think you need to pass the iterated date to the Date constructor:

dates.forEach((date) => {
  if(date.getDay() == 6) {
    console.log('sat', date)
    var t = new Date(date) // this line
    console.log('sat new', new Date(t.setDate(date.getDate() + 1)))
  }
}
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