I am having trouble adding days to a date using Google Apps Script in Google Sheets. I have the following code snippet:
for (var index = 0; index < inputData.length; ++index) {
var currentRow = inputData[index];
var vehicle = currentRow[1];
var originalDate = currentRow[2];
if ((vehicle == "VehicleA") || (vehicle == "VehicleB")) {
var updatedDate = new Date(originalDate.getTime() + (154 * 24 * 60 * 60 * 1000));
console.log(updatedDate);
}
}
I attempted to use new Date(originalDate.add({days: 154}));
but encountered an error indicating that add()
wasn’t recognized. I suspect there might be an issue with the date format in Sheets, which looks like 7/26/2014
.