请尝试以下示例:
var ddate = Utilities.formatDate(new Date(), "GMT", "MM-dd-yy");
function checkDate(){
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var rows = sheet.getDataRange();
var rowsNumber = rows.getNumRows();
var column = sheet.getDataRange();
var values = column.getValues();
for (var i = 1; i <= rowsNumber -1; i++){
var customerData = values[i];
var customerDate = customerData[2];
var myRow = Math.round(i) +1;
var conCustomerDate = Utilities.formatDate(new Date(customerDate), "GMT", "MM-dd-yy");
if (conCustomerDate > ddate){
sheet.getRange("D" + myRow).setValue("OK");
}
else {
sheet.getRange("D" + myRow).setValue("Old");
}
}
}