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

252
Vistas
Google sheets API sorting by date

I'm using nodejs with google sheets API and I'm trying to sort data by column with date string that looks like this: 'dd.mm', for example '01.03'. Currently I'm trying to do it by using batchUpdate, but it doesnt work. It sorts by day, 01 is first, 02 is second etc... My request looks like this:

await googleSheets.spreadsheets.batchUpdate({
    spreadsheetId,
    requestBody: {
      requests: [
        {
          sortRange: {
            range: {
              sheetId,
              startRowIndex,
              endRowIndex,
              startColumnIndex,
              endColumnIndex,
            },
            sortSpecs: [
              {
                dimensionIndex,
                sortOrder,
              },
            ],
          },
        },
      ],
    },
  });

How can I make google sheets API see the columns as dates, not as strings? Because I assume thats where the problem is, the date string is sorted like a normal string.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Format the range to date format of day.month in your Google Sheets.

  1. Highlight column or range you want to format.
  2. Click Format Tab -> Number -> Custom number format.
  3. In the text box, insert this value: d"."m.
  4. Click Apply.

Step by step example:

enter image description here

enter image description here

enter image description here

Google Sheets can now recognize the data as date, you can sort it now using the API.

Example:

enter image description here

Request:

{
  "requests": [
    {
      "sortRange": {
        "range": {
          "sheetId": 0,
          "startRowIndex": 0,
          "startColumnIndex": 0,
          "endRowIndex": 13,
          "endColumnIndex": 1
        },
        "sortSpecs": [
          {
            "sortOrder": "ASCENDING",
            "dimensionIndex": 0
          }
        ]
      }
    }
  ]
}

Output:

enter image description here

Reference:

  • Custom date formatting
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