1

I tried using the following script but it sends emails based on the number of rows in the outlined range. It doesn't execute if ( statement). Can someone help me, please?

function sendEmail() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("name");
  var startRow = 2;
  var numRows = 2;
  var dataRange = sheet.getRange(startRow, 2, numRows, 1);
  var data = dataRange.getValues();
  Logger.log(data)

  var currentTime = new Date();
  var month = currentTime.getMonth();
  var day = currentTime.getDate();
  var year = currentTime.getFullYear();

  for (i in data) {
    var row = data[i];
    var date = new Date();
    var sheetDate = new Date(row[2]);

    Sdate = Utilities.formatDate(date, 'GMT+0300', 'dd:MM:yyyy')
    SsheetDate = Utilities.formatDate(sheetDate.
      'GMT+0300', 'dd:MM:yyyy')
    Logger.log(Sdate + ' =? ' + SsheetDate)
    if (Sdate >= SsheetDate) {
      var emailAddress = "email address"
      var message = "sss"
      var subject = "Task Item Due";
      MailApp.sendEmail(emailAddress, subject, message);
    }
  }
}
Tanaike
  • 181,128
  • 11
  • 97
  • 165
polina
  • 11
  • 1
  • [``Utilities.formatDate()``](https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)) returns a string value. In your script, 2 string values are compared. So I think that this thread is useful for your situation. https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript – Tanaike Oct 30 '18 at 22:24

0 Answers0