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

317
Visualizações
In Google Sheets how to compare date formats of multiple cells using Apps Script / Javascript?

So I was searching for a way to compare date formats of 2 different cells and validate them.

A SO user showed me some code. We changed it in order not to use the confusing (for me) regex syntax so the user came up with something like this:

const getDateFormats = range =>
  SpreadsheetApp.getActiveSpreadsheet()
    .getActiveSheet()
    .getRange(range)
    .getNumberFormats()
    .flat();

const main = () => {
  const formatsInRange = getDateFormats('A1:A3')
  console.log(formatsInRange);
  formatsInRange.forEach((format, i) =>
    'dddd", "d" "mmmm" "yyyy' === format ||
    'dd"/"mm"/"yyyy' === format
      ? console.log(`Value ${i + 1} is OK`)
      : console.log(`Value ${i + 1} is not OK`)
  )
};

So the code above will work for 2 and 3 cells: getDateFormats('A1:A2') and getDateFormats('A1:A3').

enter image description here

enter image description here

But if I try with 4 cells or multiple cells all the way down the column with getDateFormats('A1:A4') or getDateFormats('A1:A') the console displays this error:

enter image description here

I would like to understand why this happens and what needs to be changed in order for the console to display multiple results like it does for 2 or 3 cells.

My file: https://docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/edit?usp=sharing

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

0

The answer of the question is on the comments, leaving this answer as community wiki:

The code provided was working as expected and returned the proper result.

The asking user commented that:

Oh you're right. It's working. You see yesterday I think the consoles is ok is not ok etc wasn't showing. Something changed or I was just tired. Sorry.

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