< =今天的日期也是拉未来的日期

时间:2013-10-30 22:54:53

标签: date google-apps-script

这几乎完美无缺,但不仅仅是拉动今天和过去的日期,它还能很好地拉动未来的日期。

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;

1 个答案:

答案 0 :(得分:2)

您正在比较字符串,而不是日期

考虑删除Utilities.formatDate - 这更像是一种“显示”日期的工具 - 并直接比较日期对象,它将按预期工作。