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

254
Visualizações
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 Respostas
Responde à pergunta

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 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