Date not being found in data range

I'm trying to to send an email every week and include information from a sheet in the email content. However the date is not searching correctly even though I have the date and the logs show the text matching exactly.

This is for a weekly program that volunteers can sign up on the sheet. The purpose of this is to remind any who wish to sign up to do so and provide the information on how to do that.

function sendEmails() {
  var signupSheet = SpreadsheetApp.getActive().getSheetByName("volunteers");
  var upcomingSunday = new Date( + 5*1000*60*60*24);
  var currentWeekRow = findRowByValue(signupSheet,upcomingSunday);
  if (signupSheet.getRange(currentWeekRow,2).getValues() = ""){
    var chairman = "Chairman";
    var chairman = "";
function findRowByValue(sheet,value){
  var dataRange = sheet.getRange("A1:A");
  var values = dataRange.getValues();
  for (var i = 0; i < values.length; i++) {
    for (var j = 0; j < values[i].length; j++) {     
      if (values[i][j] == value) {
        return i+1;
  return -1;

I expect the findRowByValue function to return the row with the date for upcomingSunday, but it keeps returning -1 which indicates it isn't finding it, however the log shows that it is there.



Try this:

function sendEmails() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName("volunteers");
  var rg=sh.getDataRange();//This gets the range that has all of the data on the sheet and column one is the date according to your code
  var vA=rg.getValues();//this gets the data 
  var chairman="";
  var nextSunday=getNextSunday();
  for(var i=0;i<vA.length;i++) {//vA[i][0] is column 1
    if(new Date(vA[i][0]).valueOf()==nextSunday.valueOf()) {//compare milliseconds to milliseconds
      if(vA[i][1]=="") {//this is column 2
        //not sure what this has to do with send email
        //probably want to break here


function getNextSunday() {//This finds the next sunday based upon the current date
  var t=new Date();
  while(t.getDay()!=0) {
  t.setHours(0,0,0,0);//set time to midnight
  return t;


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.