Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda