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

271
Vistas
JS getting dynamic dates for a range

I have a small snippet of JS code that I've been using to set dates on the header of an HTML table based on an object, like so:

dates() {
  const dates = [...new Set(this.rows.map(r => r.pri_date))]
  return dates.sort((a,b) => new Date(a) - new Date(b))
},

in this example, rows was just a json object

What I actually need is to set a table header of dates regardless of the dates in the object. I need the first column to be today's date, and then the following 7 days.

So right now it would look like:

2021-11-02 | 2021-11-03 | 2021-11-04 | 2021-11-05 |2021-11-06 | 2021-11-07 | 2021-11-08 | 2021-11-09

How can I change the above code to be a dynamic date range based on the current day's date (trying to keep the format and return the same in my code)

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

0

Try this:

const today = Date.now();
const dates = [
  ...this.rows.map((x,i) => {
    return new Date(today + 86400000 * i).toISOString().substring(0,10);
    // 86400000 ms is 24hours
  })
]
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