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

134
Visualizações
Get all specific day in specific end date in JavaScript

I am trying to get all day (input by me) in a specific end date (input by me).

example :

I have day 1 and I have end date 10/12/2021

beginning from new Date():

output must be: 1/10/2021 1/11/2021 1/12/2021

day 1 for this month is not included because we are in day 20 and day 20 > day 1

Same, I chose day 20 (example) and end date = 19/12/2021 day 20 in end date not included because day 20 > end date day

I have already tried that as simple using if condition, but not great work because in this case, I have 8 conditions!

I want a simple code that works for this situation.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hope that is what you wanted. You can simplify it more if you want.

const getRemainingDates = function(beginningDay, endDate){
  const today = new Date()
  const [endDateDay,endDateMonth,endDateYear] = endDate.split("/");
  const remainingMonth = endDateMonth - (today.getMonth()+1);
  for(let i = 0; i <= remainingMonth; i++){
    if(i === 0){
        if(beginningDay>today.getDate() && beginningDay>endDateDay){
          console.log(`${beginningDay}/${today.getMonth()+1+i}/${today.getFullYear()}`)
        }
        else {}
    }
    if(i !== 0)console.log(`${beginningDay}/${today.getMonth()+1+i}/${today.getFullYear()}`)
  }
}

getRemainingDates(21,"12/12/2021");
console.log()
getRemainingDates(1,"12/12/2021");

about 4 years ago · Juan Pablo Isaza Relatório
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