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

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

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