3
votes

I'm looking to compare dates pulled from a spreadsheet to today's date, using this post as a reference: How do I compare dates with a spreadsheet using Google Apps Script?

When I run the script, I get a 'Cannot find function getTime() in object' message for the line that declares var dataDay (first line after for loop).

When I run the debugger, the values in the position values[i][18] though say it is a date object. Any thoughts here?

function gantChart() { 
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Copy of 2016 Gift Tracking");
  var values = ss.getRange(3,1,ss.getLastRow(),ss.getLastColumn()).getValues();
  var day = 24*3600*1000
  var today = parseInt((new Date().setHours(0,0,0,0))/day);
  var destSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Get chart automation");
  for (var i=0; i < values.length; i++) {
    var dataDay = parseInt(values[i][18].getTime()/day);
    if(dataDay > today) {
     }
  } 
  debugger;
}
1
try replacing values[i][18] with new Date(values[i][18]) - Serge insas
Worked like a charm! Thanks, Serge. Also, I'm excited to dive into your book! - coachpacman

1 Answers

0
votes

From a comment by Serge insas

try replacing values[i][18] with new Date(values[i][18])