Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

318
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda