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

203
Visualizações
Javascript How to increase Month when Date is over today month

i really stuck at this date. Let say today is 01 20 2021, and i want to add 14 day later to get expired date. so for the expired date should be 02 03 2021, but i only get 01 03 2021. Can anyone help me on this. Thanks

this is my code

    var today = new Date();
  
    var monthIndex = today.getMonth()+1;
    var year = today.getFullYear();

    var addday = new Date(new Date('1.20.2021').getTime()+(14*24*60*60*1000));
    var nextDay = addday.getDate();
    var nextMonth = monthIndex;
    console.log('day',day)
    
    return nextMonth+'.'+nextDay+'.'+year
 
    //the return that I want is 2.03.2021


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

0

You didnt update the value for monthIndex. You must use:

var nextMonth = addday.getMonth()+1;
about 4 years ago · Juan Pablo Isaza Relatório

0

Just use Date.setDate function for this.

// new Date('1.20.2021') => Jan 20 2021
const dateStr = '1.20.2021';
const [mm, dd, yyyy] = dateStr.split('.');
const today = new Date(yyyy, +mm-1, dd);
// add 14 days
const newDate = new Date(new Date(today).setDate(today.getDate() + 14));
console.log(`Today: ${today}`);
console.log(`New Date: ${newDate}`);
console.log(newDate.getMonth() + 1 + '.' + newDate.getDay() + '.' + newDate.getFullYear());

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