Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
toLocaleDateString validation issue with Javascript

I am working on verifying the date, if it is present in between 2 dates, written following code to to validate dates. For few dates it is resulting invalid date even though the date is present in between the date range. Not sure what i am doing wrong here, anyone help me to resolve this.

Issue Dates : "2022-06-04", "2022-06-05", "2022-06-06", "2022-06-07", "2022-06-08", "2022-06-09"

Thank you

const dates = ["2022-05-01", "2022-05-02", "2022-05-03", "2022-05-04", "2022-05-05", "2022-05-06", "2022-05-07", "2022-05-08", "2022-05-09", "2022-05-10", "2022-06-01", "2022-06-02", "2022-06-03", "2022-06-04", "2022-06-05", "2022-06-06", "2022-06-07", "2022-06-08", "2022-06-09", "2022-06-10", "2022-06-11", "2022-06-12", "2022-06-13", "2022-06-14", "2022-06-15", "2022-06-16", "2022-06-17", "2022-06-18", "2022-06-19", "2022-06-20"];

dates.forEach(function (item) {
  const recordDate = new Date(item).toLocaleDateString();
  console.log(recordDate);
  date1 = new Date("Sunday, May 3, 2022"); // from an input field
  date2 = new Date("Thursday, June 20, 2022"); // from an input field
  startDate = new Date(
    date1.getFullYear(),
    date1.getMonth(),
    1
  ).toLocaleDateString(); // start of month from date1 '5/1/2022'
  endDate = new Date(
    date2.getFullYear(),
    date2.getMonth() + 1,
    0
  ).toLocaleDateString(); // end of month from date2 '6/30/2022'
  if (recordDate >= startDate && recordDate <= endDate) {
    console.log("valid");
  } else console.log("not valid");
});
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda