Google Sheets recipe
How to sort by date in Google Sheets
Use =SORT(range, date_column, TRUE) for oldest first, or FALSE for newest first. Dates written as text sort alphabetically instead, so check them with ISNUMBER and convert with DATEVALUE. SORTN returns only the latest N rows.
Steps
- Put the dates in one column of real dates, for example B2:B6, with a header in row 1. Test one cell with ISNUMBER: TRUE means it is a date, FALSE means it is text.
- Write =SORT(A2:C6, 2, TRUE) in an empty cell. The 2 is the position of the date column inside the range, and the header row stays out of the range.
- Change TRUE to FALSE for newest first.
- Add a second key after the first to break ties, as in the third example: SORT(A2:C6, 2, TRUE, 3, FALSE) sorts by date, then by amount from largest to smallest.
- For the latest N rows, use SORTN as in the fourth example. Give the date key with FALSE and a second key so equal dates do not leave the cut to chance.
- If ISNUMBER says FALSE, sort by DATEVALUE(range) as in the last example. DATEVALUE reads the text with the locale of the file, so test one value first.
- To reorder the cells themselves instead of getting a formula result, select A2:C6 and use Data → Sort range. The API test below applied the same sort and read the cells back.
Examples
The examples use this table, starting in A1:
| Order | Date | Amount |
| O1 | 2026-03-14 | 120 |
| O2 | 2026-01-09 | 80 |
| O3 | 2026-11-05 | 45 |
| O4 | 2026-03-14 | 200 |
| O5 | 2026-02-21 | 60 |
=SORT(A2:C6, 2, TRUE)Result:
| O2 | 2026-01-09 | 80 |
| O5 | 2026-02-21 | 60 |
| O1 | 2026-03-14 | 120 |
| O4 | 2026-03-14 | 200 |
| O3 | 2026-11-05 | 45 |
Oldest first. The date column is the second column of the range, TRUE means ascending. The header row stays out of the range.
Run in a Google Sheet (English US locale) on .
=SORT(A2:C6, 2, FALSE)Result:
| O3 | 2026-11-05 | 45 |
| O1 | 2026-03-14 | 120 |
| O4 | 2026-03-14 | 200 |
| O5 | 2026-02-21 | 60 |
| O2 | 2026-01-09 | 80 |
Newest first: the same formula with FALSE for descending order.
Run in a Google Sheet (English US locale) on .
=SORT(A2:C6, 2, TRUE, 3, FALSE)Result:
| O2 | 2026-01-09 | 80 |
| O5 | 2026-02-21 | 60 |
| O4 | 2026-03-14 | 200 |
| O1 | 2026-03-14 | 120 |
| O3 | 2026-11-05 | 45 |
Two columns. Rows sort by date first. When two rows share a date, the larger amount goes first, so O4 comes before O1 on 2026-03-14.
Run in a Google Sheet (English US locale) on .
=SORTN(A2:C6, 2, 0, 2, FALSE, 3, FALSE)Result:
| O3 | 2026-11-05 | 45 |
| O4 | 2026-03-14 | 200 |
The two most recent rows. SORTN keeps the first 2 rows of the descending date order. The amount key breaks the tie between the two 2026-03-14 rows.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(ISNUMBER(B2:B6)&" / "&ISTEXT(B2:B6))Result:
| FALSE / TRUE |
| FALSE / TRUE |
| FALSE / TRUE |
| FALSE / TRUE |
| FALSE / TRUE |
The same column, but the dates were written as text such as 2026-3-14. ISNUMBER says FALSE and ISTEXT says TRUE on every row, so these are not dates yet.
Run in a Google Sheet (English US locale) on .
=SORT(A2:C6, 2, TRUE)Result:
| O2 | 2026-1-9 | 80 |
| O3 | 2026-11-5 | 45 |
| O5 | 2026-2-21 | 60 |
| O1 | 2026-3-14 | 120 |
| O4 | 2026-3-14 | 200 |
Sorting the text column. The order is alphabetical, not chronological: 2026-11-5 lands before 2026-2-21 and 2026-3-14 comes last.
Run in a Google Sheet (English US locale) on .
=SORT(A2:C6, ARRAYFORMULA(DATEVALUE(B2:B6)), TRUE, 3, FALSE)Result:
| O2 | 2026-1-9 | 80 |
| O5 | 2026-2-21 | 60 |
| O4 | 2026-3-14 | 200 |
| O1 | 2026-3-14 | 120 |
| O3 | 2026-11-5 | 45 |
The fix. DATEVALUE turns each text into a date number and SORT uses that array as the sort key. The cells stay as they are, and the rows now come out in date order.
Run in a Google Sheet (English US locale) on .
Common errors
- Text dates sort as text. In the sixth example 2026-11-5 comes before 2026-2-21, because the comparison goes character by character. ISNUMBER on the column shows FALSE for every row.
- The same happens with the Data → Sort range menu. The sortRange test on text dates gave O2, O3, O5, O1, O4, the alphabetical order, in both files. The same test on real dates gave O2, O5, O1, O4, O3.
- The text 03/04/2026 is March 4 in an en_US file and April 3 in an ro_RO file. A text like 15/01/2026 gives #VALUE! in en_US and a valid date in ro_RO, so check the locale in File → Settings before converting.
Compared with Excel
Not the same method. Excel 365 has SORT, but the order is 1 or -1 instead of TRUE or FALSE, and SORTN does not exist there. DATEVALUE exists in Excel and also reads text with the regional settings.