Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!