function reminder() { var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet() var data = sh.getDataRange().getValues() var d = new Date().getTime(); for (var i=1;i<data.length;i++){ if (data[i][4]<=new Date(d+7*24*60*60*1000) && data[i][4]>=new Date(d+5*24*60*60*1000) && data[i][6]==''){ MailApp.sendEmail({to:data[i][3], subject: 'Reminder Process Update Required in 1 week', htmlBody: 'Hello '+data[i][1]+' The page for '+data[i][0]+' is due to review on '+data[i][4]+' Please review the content and contact the team before its due date if amendments are required.' }) sh.getRange(i+1,7).setValue('sent') } else if (data[i][4]<=new Date(d+30*24*60*60*1000) && data[i][4]>=new Date(d+28*24*60*60*1000) && data[i][5]==''){ MailApp.sendEmail({to:data[i][3], subject: 'Reminder Process Update Required in 1 month', htmlBody: 'Hello '+data[i][1]+' The page for '+data[i][0]+' is due to review on '+data[i][4]+' Please review the content and contact the team before its due date if amendments are required.' }) sh.getRange(i+1,6).setValue('sent') } } }¿Cómo puedo cambiar el formato de la fecha en mi secuencia de comandos? Actualmente está generando un correo electrónico automático, sin embargo, la fecha se está formateando y muestra la hora y (hora estándar del este) Me gustaría que solo muestre la fecha sin la hora incluida.
Puede crear una función de formato como
function formatDate(d) { return `${String(d.getDate()).padStart(2, '0')}/${String(d.getMonth() + 1).padStart(2, '0')}/${d.getFullYear()}`; }Ejemplo:
function formatDate(d) { return `${String(d.getDate()).padStart(2, '0')}/${String(d.getMonth() + 1).padStart(2, '0')}/${d.getFullYear()}`; } const i = 0; const data = [['Client', 'Recipient',,, new Date()]]; console.log('Hello '+data[i][1]+' The page for '+data[i][0]+' is due to review on '+formatDate(data[i][4])+' Please review the content and contact the team before its due date if amendments are required.');llame a esta función donde necesita la fecha formateada.
function formatDate(date) { var d = new Date(date), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); if (month.length < 2) month = '0' + month; if (day.length < 2) day = '0' + day; return [ day, month, year].join('/'); }Si bien hay otras formas de formatear una fecha, una forma más directa, basada en Apps Script, es usar Utilities.formatDate :
const formattedDate = Utilities.formatDate(data[i][4], Session.getTimeZone(), "dd/MM/yyyy"); Simplemente agregue esta línea justo antes de enviar el correo electrónico y reemplace data[i][4] con formattedDate en el htmlBody .