I am trying to write a code that get data from Google Sheet and send emails. However, when I try to get date as dd-mm-yyyy, in the mail it seems "Wed Feb 23 2022 16:00:00 GMT-0500 (Eastern Standard Time)
function sendEmails() {
var EMAIL_SENT = 'Mail Yollandı';
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lr = ss.getLastRow();
var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange(1,1).getValue();
for(var i = 2;i<=lr; i ){
var MailAddress = ss.getRange(i,1).getValue();
var RaporBaslangic = ss.getRange(i,2).getValue();
var RaporBitis = ss.getRange(i,3).getValue();
var checklist = ss.getRange(i,4).getValue();
if(checklist !== EMAIL_SENT){
var currentText = templateText.replace("{Rapor Başlangıç Tarihi}",RaporBaslangic).replace("{Rapor Bitiş Tarihi}",RaporBitis);
if (checklist !== EMAIL_SENT) { // Prevents sending duplicates
MailApp.sendEmail(MailAddress,"Sağlık Raporlarının İadesi - Revize",currentText)
ss.getRange(i, 4).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
}
CodePudding user response:
If the date is included in your sheet, use .getDisplayValue()
instead of .getValue()
If you want by script to add the date, use
var d = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd-MM-yyyy");