Reputation: 1
This works almost perfectly but instead of only pulling dates that are today and in the past it pulls future dates well.
function checkStatus(objectArray) {
var resultArray = [];
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dashboardSheet = ss.getSheetByName('Dashboard');
//loads the standing today's date from the dashboard sheet, which is stored in cell E10
var checkDateToday = Utilities.formatDate(dashboardSheet.getRange('E10').getValue(), 'PST', 'mm/dd/yyyy');
for (var i=0; i<objectArray.length ; i++) {
var resultObject = objectArray[i];
var publishDate = Utilities.formatDate(resultObject.publishDate, 'PST', 'mm/dd/yyyy');
if(( resultObject.qcStatus == "Partner fix" || resultObject.qcStatus == "ordered") && (publishDate <= checkDateToday)){
resultArray.push(resultObject);
}
}
return resultArray;
Upvotes: 0
Views: 71
Reputation: 46822
You are comparing strings, not dates.
Consider removing the Utilities.formatDate
- that is more a tool to "show" dates the way you want - and compare the date objects directly and it will work as expected.
Upvotes: 2