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

174
Visualizações
Embed function inside of IF statement Google sheets

This function works well, thanks to Michael the Temp. But how can it work if embedded inside of an IF statement like so: =IF(B2>5, TIMESTAMP(), "FALSE")

function TIMESTAMP() 
 {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getActiveSheet();
   var addedDateAndTime = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm:ss");
   //Optional if you only want the date: var addedDate = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "dd/MM/yyyy");
   //Optional if you only want the time: var addedTime = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "hh:mm:ss");
   sheet.getRange(1,1).setValue(addedDateAndTime)
   }
...
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

hey @user17712179 welcome! you can try this:

function TIMESTAMP() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var addedDateAndTime = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm:ss");
    //Optional if you only want the date: var addedDate = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "dd/MM/yyyy");
    //Optional if you only want the time: var addedTime = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "hh:mm:ss");
    if (sheet.getRange("B2").getValue() > 5) {
        sheet.getRange(1,1).setValue(addedDateAndTime);
    } else {
        sheet.getRange(1,1).setValue('FALSE');
    };
}

Let me know!

about 4 years ago · Juan Pablo Isaza Relatório

0

Depending on your needs, you can also make AJ formula more reusable by adding params to the custom function and passing cell data to your formula.

 /**
 * Convert cell value in timestamp
 *
 * @param {cell} input The value to convert.
 * @return Timestamp converted.
 * @customfunction
 */

function TIMESTAMP(cell) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var addedDateAndTime = Utilities.formatDate(new Date, ss.getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm:ss");
  if (cell > 5) {
    return addedDateAndTime
  } else {
    return 'FALSE'
  };
}
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