1
I’m trying to subtract two dates. Today’s date, using the new Date(), and a date from a googledocs(photo) spreadsheet. Column F that stores the dates of googledocs is in the dd/mm/yyyy date format. When executing the script, I have Typeerror: Cannot find the getTime function in the object . (line 21, file "Code") The line 21 is highlighted below, and I saw that the problem is in the variable dFim (which stores the date of the table), because when I removed it, the code ran without error. This variable stores the read value of column F. I’m using getTime() to get the milliseconds of the interval and divide them by milliseconds of a day as the manual says and I don’t know where I might be missing?
function myFunction() {
ss = SpreadsheetApp.getActiveSpreadsheet();
var dataRange = ss.getDataRange();
var values = dataRange.getValues();
var today = new Date();
for (var i = 4; i < values.length; i++) {
var dFim = values[i][5];
var dias = (today.getTime() - dFim.getTime()) / 86400000; //linha 21
if (dias > 0) {
Logger.log('Projeto atrasado')
} else {
Logger.log('Projeto no prazo')
}
}
}
If I enter a date directly as you did, '07/03/2019', it runs normal. However, the way the first code is, it returns the error: Typeerror: It is not possible to find the split function in the Fri object Feb 15 2019 00:00:00 GMT-0500 (EST). (line 10, file "Code") This date is from the spreadsheet
– roger roger
Got it... I’ll take a look.
– Sam
Do this, put one
console.log(dFim);
after the linevar dFim = values[i][5];
and tell me what it shows.– Sam
Try this: leave your code as it was, just change this line:
var dFim = new Date(values[i][5]);
– Sam
See the console thing I mentioned above.
– Sam
Let’s go continue this discussion in chat.
– Sam
Solved by changing the variable dFim to var dFim = new date(values[i][5]), as suggested in the chat and above. Thank you very much.
– roger roger