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.
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