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

115
Vistas
Check if an array contains Date, that is between Two Dates in the second array

I have two arrays.

let dateArray = ['2018-05-04T00:00:00+01:00', '2019-04-20T00:00:00+01:00', '2020-05-29T00:00:00+01:00'];

let rangesArray = [['2021-09-01','2022-09-01'],['2019-09-01','2020-09-01']];

How to check if the dates from dateArray are between the dates in rangesArray.

rangesArray[0] is first range - Im interested in dates between 2021-09-01 and 2022-09-01.

rangesArray[1] is second range - Im interested in dates between 2019-09-01 and 2020-09-01.

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

0

use Date.parse() to convert string to date for comparison.

working example:

function dateCheck(from, to, check) {
  var fDate, lDate, cDate;
  fDate = Date.parse(from);
  lDate = Date.parse(to);
  cDate = Date.parse(check);

  if (cDate <= lDate && cDate >= fDate) {
    return true;
  }
  return false;
}

let dateArray = [
  "2018-05-04T00:00:00+01:00",
  "2019-04-20T00:00:00+01:00",
  "2020-05-29T00:00:00+01:00",
];

let rangesArray = [
  ["2021-09-01", "2022-09-01"],
  ["2019-09-01", "2020-09-01"],
];

for (let i = 0; i < dateArray.length; i++) {
  for (let j = 0; j < rangesArray.length; j++) {
    console.log(dateCheck(rangesArray[j][0], rangesArray[j][1], dateArray[i]));
  }
}

explanation: dateCheck function checks if the date is between from date and to date. with two loops you can get the result that you want.

about 4 years ago · Juan Pablo Isaza Denunciar

0

One way :

let dateArray = ['2018-05-04T00:00:00+01:00', '2019-04-20T00:00:00+01:00', '2020-05-29T00:00:00+01:00'];

let rangesArray = [['2021-09-01','2022-09-01'],['2019-09-01','2020-09-01']];

const res = []
dateArray.forEach(d => {
  rangesArray.forEach(a => {
    if ((new Date(d) >= new Date(a[0])) && (new Date(d) <= new Date(a[1]))){
      res.push({date: d, range: a[0] + ' ' + a[1]})
    }
  })
})

console.log(res)

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