0
votes

I am using a email sending script below to send out some dates to people that are authorized, in the google sheet its formatted

DD/MM/YYYY

however whats being sent is a long date with time attached like this

"Mon Jan 07 2019 00:00:00 GMT-0000 (GMT)"

I simply need it to send exactly what is in the cell with out changing it,I have tried a few things not worked so far, I don't want to change whats in the sheet simply just send whats shown.

Any help would be very much appreciated

The script is

// Scrips for Email sheet PHC main 
// has been sent successfully.
var EMAIL_SENT = "SENT";

function sendEmailshol() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2;  // First row of data to process
  var numRows = 5;   // Number of rows to process
  // Fetch the range of cells 
  var dataRange = sheet.getRange(startRow, 1, numRows, 50) ;  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var emailAddress = row[42] ;  // First column
    var message = 'Hi ' + row[3] + '\n'// Hi then Name from sheet then new line 
    + 'xxx.' + '\n\n' 
    + row[5] + ' To ' + row[6] + ' ' + row[7] + '\n' 
    + '\n\n' 
    + 'Any questions please dont hesitate to give me a call.' + '\n\n' 
    var emailSent = row[43];     // Third column
    if (emailSent != EMAIL_SENT) {  // Prevents sending duplicates
      var subject = 'xxx' ;
      MailApp.sendEmail(emailAddress, subject, message);
      sheet.getRange(startRow + i, 44).setValue(EMAIL_SENT);       // Make sure the cell is updated right away in case the script is interrupted
      SpreadsheetApp.flush();
    }
  }
}
1

1 Answers

2
votes

You can checkout here, https://developers.google.com/google-ads/scripts/docs/features/dates , about Date formating.

Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd'T'HH:mm:ss'Z'");

So in your case it would be...

var formatedDate = Utilities.formatDate(unFormatedDate, yourTimeZone, "DD/MM/YYYY");

Hope it would help :)