I'm not sure what I'm doing wrong here, and this is probably really simple... After scouring the net and trying hundreds of different examples found, I've come up empty handed on getting the format needed. My script works, sends the email, all values are there, but the date formats are not what we are after. So, here is what's up:
I've got a basic script that sends an HTML email from a template when a respondent submits a form. The timestamp, start (date and time), end (time only) value is needed, and is printed in the HTML email, but it's showing a full-blown timestamp output such as: "Tue Nov 03 2020 11:39:28 GMT-0700 (Mountain Standard Time)"
What I am trying to do is format the timestamp value shown in the email to this: "Tue Nov 03 2020 HH:mm"
Here is the script I am using:
function onFormSubmit(e) {
var htmlBody = HtmlService.createTemplateFromFile('email');
var rng = SpreadsheetApp.getActiveSheet().getActiveRange();
var timestamp = Utilities.formatDate(new Date(), "MST" , "MM-dd-yyyy | HH:mm:ss");
var email = rng.getValues()[0];
var body = HtmlService.createTemplateFromFile("email");
var to = 'foo@bar';
var subject = 'Activity Report ' + email[0] + '';
htmlBody.timestamp = email[0];
htmlBody.start = email[1];
htmlBody.end = email[2];
htmlBody.activityobserved = email[3];
htmlBody.summary = email[4];
htmlBody.actiontaken = email[5];
htmlBody.attachments = email[6];
var email_html = htmlBody.evaluate().getContent();
MailApp.sendEmail({
to: to,
subject: subject,
htmlBody: email_html,
replyTo:'bar@foo',
});
}
timestamp, but you're not using it anywhere.htmlBody.timestamp = email[0];tohtmlBody.timestamp = timestamp;and this seems to work great.Utilities.formatDate()call when settinghtmlBody.startandhtmlBody.end.