Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!