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

300
Vistas
How to get the date for a specific day using javascript

Using the current date new Date(), I would like to calculate the date for the following Wednesday using Javascript.

For example, the current date is today:

"Sun Apr 18 2022 15:00:00 GMT"

What I would like to do is get the date for the following Wednesday, which would be:

"Wed Apr 20 2022 15:00:00 GMT"

If the current day is a Wednesday, I would like to calculate the date for the following Wednesday.

How could I achieve this?

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

0

Use the getDay method which will give day of the week (0 - 6, from sunday to saturday). (Wednesday is day 3)

function nextWednesday(date) {
  const day = date.getDay();
  // getDay returns between 0 - 6. Sunday - Saturday.
  // 3 is Wednesday
  let daysToAdd = 0;
  if (day < 3) {
    daysToAdd = 3 - day;
  } else {
    daysToAdd = 7 - day + 3;
  }
  return new Date(date.getTime() + daysToAdd * 24 * 60 * 60 * 1000);
}


const today = new Date();

console.log('today: ', today.toString());
console.log('following wednesday: ',  nextWednesday(today).toString())

about 4 years ago · Juan Pablo Isaza Denunciar

0

Whenever I need to find something in JavaScript, I search the internet and prefix "mdn " to search the Mozilla development site. For example, searching Google for "mdn weekday" will give a result pointing to documentation for Date.prototype.getDay().

I would likely end up with something like this:

function daysToWednesday(dt) {
  const day = Date(dt).getDay();
  if (day < 3) {
    return 3 - day;
  } else {
    return 10 - day;
  }
}

function nextWednesday(dt) {
  const ret = Date(dt);
  ret.setDate(ret.getDate() + daysToWednesday(ret));
  return ret;
}
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