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

158
Visualizações
getMonth problem with Google Sheets javascript

getMonth is not a function in this code for Google Sheets:

... Logger.log(ss.getSheetByName("Rendimentos").getRange(aportes-cont,3).getValue().getMonth());

while (ss.getSheetByName("Rendimentos").getRange(aportes-cont,3).getValue().getMonth()===numMes){ ... }

The Logger.log line works perfectly. It shows the number of the month required. But the second line show a message error: getMonth() is not a function.

It just don't make sense the same code works inside the Logger.log, but get stucked inside the while loop.

I don't know what to do.

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

0

The error occurs when the original cell does NOT contain the date. In this case, the .getMonth() method tries to determine the month from a value that is not the date. Try replacing your code with the following:

let rangeData = ss.getSheetByName("Rendimentos").getRange('C:C').getValues().flat();    
while (new Date(rangeData[aportes-cont]).getMonth()===numMes){ 
  ... 
}

It is also good practice to reduce the number of times the script accesses the google sheets data - so in the suggested code I first read the data of the entire column C once, and then work with the resulting data as elements of an array

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