S
S
Scampy2018-05-08 21:44:59
Google Apps Script
Scampy, 2018-05-08 21:44:59

How to change date format in script?

Hello! There is such a script for sending form responses to mail.
You need to change the date format to (yyyy/MM/dd). Help plz!
Apparently it is necessary to do with the help of "Utilities.formatDate"

function sendFormByEmail(e)
 {    
// instance of Active Spreadsheet:
var responceSheet = SpreadsheetApp.getActiveSheet();

// number of rows in responce form:
var rows = responceSheet.getLastRow();

// range of dates, e-mails:
var date = responceSheet.getRange(rows, 3, 1, 1);
var email = responceSheet.getRange(rows, 8, 1, 1);

// last sender's name, e-mail::
var emailSender = email.getValue();
var dateSender = date.getValue();

// message subject, body:
var subject = "Test";
var body = "Test " + dateSender;

// send the e-mails:
MailApp.sendEmail(emailSender, subject, body);
 }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Samokhin, 2018-05-10
@Scampy

Try
var dateSender = Utilities.formatDate(date.getValue(), "GMT+03", "yyyy/MM/dd");
or
var dateSender = Utilities.formatDate(new Date(date.getValue()), "GMT+03", "yyyy/MM/dd");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question