Home > Mobile >  Script calls newDate and adds 5 days. I am looking to format the output to just date
Script calls newDate and adds 5 days. I am looking to format the output to just date

Time:07-06

Script for current date 5 sends an email with exact 5 days from now. I want this to only output the date leaving out the timestamp

current output is: Sun Jul 10 2022 09:29:16 GMT-0400 (Eastern Daylight Time)

expected output is: 07/0/2022

Here is what I have tried.

function findEmailAddress() {
  var ss = SpreadsheetApp.getActive();
  var sh1 = ss.getSheetByName('Working');
  var vs1 = sh1.getRange('H1:H'   sh1.getLastRow()).getValues().flat();
  var sh2 = ss.getSheetByName('Match');
  var vs2 = sh2.getRange('A2:B'   sh2.getLastRow()).getValues();
  var matchRows = vs2.filter(row => row[0].length && vs1.includes(row[0]));
  matchRows.forEach(row => {
    var mailMatch = row[1];
    var curDate = new Date();
      var date5 = curDate.setDate(curDate.getDate()   5);
      var dateFormat = moment(date5).format('DD/MM/YY');
      var sub = "Action Required!!!  5 Days Til Expiration"
      var bod = 'You have a new expiration date for completion' 
        dateFormat   ' all tasks associated with this must be complete. *This email is automatically generated do not reply*'
    GmailApp.sendEmail(mailMatch, sub, bod);
  });
}

I am stumped as to why this doesn't work.

CodePudding user response:

Try it this way:

function findEmailAddress() {
  var ss = SpreadsheetApp.getActive();
  var sh1 = ss.getSheetByName('Working');
  var vs1 = sh1.getRange('H1:H'   sh1.getLastRow()).getValues().flat();
  var sh2 = ss.getSheetByName('Match');
  var vs2 = sh2.getRange('A2:B'   sh2.getLastRow()).getValues();
  var matchRows = vs2.filter(row => row[0].length && vs1.includes(row[0]));
  matchRows.forEach(row => {
    var mailMatch = row[1];
    var curDate = new Date();
      curDate.setDate(curDate.getDate()   5);
      let d = Utilities.formatDate(curDate,Session.getScriptTimeZone(),"MM/dd/yyyy")
      var sub = "Action Required!!!  5 Days Til Expiration"
      var bod = 'You have a new expiration date for completion' 
        d   ' all tasks associated with this must be complete. *This email is automatically generated do not reply*'
    GmailApp.sendEmail(mailMatch, sub, bod);
  });
}
  • Related