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

153
Visualizações
Getting an 'Is not a Function Error' when calculating the months with Moment JS

Here is my Fiddle http://jsfiddle.net/p1kr0ayj/2/


function letsGo() {
  //for the inputs
  let name = document.querySelector('#inputName').value;
  let date = document.querySelector('#inputDate').value;
  let welcm = document.getElementById("welcome").innerHTML;
  let errorpopup = document.getElementById("error");
  let animation = document.getElementsByClassName("anim")[0];

  let currDate = moment().format("MM-DD-YYYY");
  console.log(currDate);
  let getDate = moment(date, "MM-DD-YYYY");
  if (getDate.isValid()) {
    //for the name
    welcm = "Welcome " + name;
    //calculating years
    yr = currDate.diff(getDate, 'years'); //heres the error
    getDate.add(yr, 'years');
    //calculating motnhs
    month = currDate.diff(getDate, 'months');
    getDate.add(month, 'months');

    console.log("nays", yr, month, currDate);
  } else {
    errorpopup.innerHTML = "Check Date";
    animation.classList.add('animError');
  }
  //console.log(getDate, errorpopup);
}

My target here is to get the total month difference not the total months since the year inputted. like the answer in the question below.

I tried to follow on what's on the documentation still gets this not a function error.

I tried to follow this Question Moment.js - Get difference in two birthdays in years, months and days

Still gets the error.

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