Only Google Apps Script product engineers could answer why, but based on the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date length is not a property of the Date object.
When using Logger.log or console.log to print any object to the IDE executions log, they will try to convert that object into a string according to the rules set to do that but Google Apps Script documentation doesn't provide details of what will be displayed when non string is passed. As you can see in the bottom each method have different results, Logger.log shows the same result as use Date.prototype.toString() while console.log prints the date time including the IATA timezone name.
JSON.stringify and Utilities.formatDate are methods for formatting Date object as strings, both work with the old and the new runtime. When using the default runtime (V8) you might also might other Date properties like Date.prototype.toDateString among others.
Please bear in mind that Date.prototype.toLocaleString will return the a result based on the server, on the user computer.
When using Google Sheets, please bear in mind that it has a different way to handle dates values than JavaScript. When using getValue / getValues Google Apps Script converts spreadsheet dates into a JavaScript Date objects based on the spreadsheet timezone. By the other hand getDisplayValue / getDisplyVAlues returns cell displayed values as string. You might use the number formatting options to format the date with certain limitations like not being able to display the timezone as the spreadsheet dates don't included it directly.
function myFunction() {
const date = new Date();
Logger.log(date);
Logger.log(date.length);
console.log(date);
console.log(date.length);
}
10:39:27 AM Notice Execution started
10:39:27 AM Info Thu Mar 03 11:39:27 GMT-05:00 2022
10:39:27 AM Info null
10:39:27 AM Info Thu Mar 03 2022 11:39:27 GMT-0500 (Eastern Standard Time)
10:39:27 AM Info undefined
10:39:27 AM Notice Execution completed
References
nulloftab[0][8].lengthis due to that the value is the date object. If you want to retrieve the length of the cell value, how about modifyingvar tab = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();tovar tab = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();tovar tab = sheet.getRange(1, 1, sheet.getLastRow(), sheet.getLastColumn()).getDisplayValues();? By this, the cell values are retrieved as the string. By this,lengthreturns the value except fornull..LocaleString()and can get the length..getDisplayValues()the value changes toDec-21and the length given is now 6, but it seems to be considerably slower to fetch the data from the sheet with this method and I won't be able to do operations on the date itself (like add a month) as it is now a stored as a string in my array.