Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

319
Visualizações
How can I change the formatting of my date within my script, would like it to show dd/mm/yyyy only
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')
    }
  }
}

How can I change the date formatting in my script, It is currently generating an automated email however the date is being formatted and showing the Time as well as (Eastern Standard Time) I would like it to only show the date without the time included.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You can create a format function like

function formatDate(d) {
  return `${String(d.getDate()).padStart(2, '0')}/${String(d.getMonth() + 1).padStart(2, '0')}/${d.getFullYear()}`;
}

Example:

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.');

about 4 years ago · Juan Pablo Isaza Relatório

0

call this function where you need formatted date.

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('/');
}
about 4 years ago · Juan Pablo Isaza Relatório

0

While there are other ways to format a date, a more direct, Apps Script-based way to do this is using Utilities.formatDate:

const formattedDate = Utilities.formatDate(data[i][4], Session.getTimeZone(), "dd/MM/yyyy");

Just add this line right before sending the email and replace data[i][4] with formattedDate in the htmlBody.

Reference:

  • Utilities.formatDate
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda