My Google Sheets spreadsheet has a list of appointments that I am trying to compare with tomorrow's date (so that I can send a reminder the day before). My current code is returning true on certain dates that aren't on the spreadsheet. We have no appointments on Sundays and I am currently testing this on a Saturday but still receiving some true values. I searched the spreadsheet thoroughly for a possible booking mistake but there are none. I did notice, however, that when it looks for the date 4:24:2016 (which is tomorrow) it will return true on 4:14:2016 dates. I am pretty much stumped at this point.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var apptDates = sheet.getRange(2, 32, sheet.getLastRow() - 1, 1).getValues();
for (var i = 0; i <= apptDates.length; i++) {
var apptDate = new Date(apptDates[i][0]);
apptDate = apptDate.addHours(74);
function dayAway(date, day) {
return new Date(date.getTime() + day * (24 * 3600 * 1000));
}
Logger.log(apptDate >= dayAway(new Date(), 1));
}
}