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

317
Visualizações
JavaScript - Date function throwing "is not a function" error

I am very new to JavaScript and it took me some time to come up with the following function in order to get current date and subtract a year from it:

function getDate() {
    var now = new Date();
    // get current timezone specific date/time
    // timezoneoffset value converts returned offset value to milliseconds
    // get current date value - 1 year
    var dateMinusOneYear = new Date(now.getTime() - 31556952000) + (now.getTimezoneOffset() * 60000);
    var dateStr =
        ("0000" + (dateMinusOneYear.getFullYear())).slice(-4) + "-" +
        ("00" + (dateMinusOneYear.getMonth() + 1)).slice(-2) + "-" +
        ("00" + dateMinusOneYear.getDate()).slice(-2);
    return (dateStr);
}

When I invoke the function, I get the following error: TypeError: dateMinusOneYear.getFullYear is not a function

Can anyone please advise? Some might advise to not use the new Date method at all due to problematic reasons, but I have to use it specifically for some unrelated reasons.

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

0

This makes no sense at all

 new Date(now.getTime() - 31556952000) + (now.getTimezoneOffset() * 60000);

Maybe you were trying to accomplish this?

   new Date(now.getTime() - 31556952000 + now.getTimezoneOffset() * 60000);
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