Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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);
  });
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading