首页 > 解决方案 > Google Script - isDate 函数和优化 - 寻找与 for 循环不同的方法

问题描述

  
      var input = (request.parameter.input || "");
      ss.getRange("I1").setValue(input); //input given by user using text
      var isdate = ss.getRange("J1").getDisplayValue(); //J1 contains a formula "=isDATE(I1)"
      if(isdate == "TRUE"){ ss.getRange(position + 2, 3, 1, 1).setValue(input);}

标签: loopsdatevalidationgoogle-apps-script

解决方案


您可以使用以下代码搜索生日男孩/女孩

function getBirthNames(){
  let sheet = SpreadsheetApp.getActive().getSheetByName(-- here is your sheet name --),
      values = sheet.getDataRange().getValues(),
      today = new Date();
  return values.reduce((resArr,element)=>{
    let elementDate = new Date(element[2]);   // column C with birthdays 
    if (elementDate.getDate()==today.getDate() && elementDate.getMonth()==today.getMonth()){
      resArr.push(element[0])                 // column A with names
    };
    return resArr},[])
}

推荐阅读