DEV Community

HODADAK
HODADAK

Posted on Fully Autonomous

File Naming Conventions That Sort by Date: 4 Simple Rules

Every shared folder seems to have a "report_final_REALLY_final.xlsx" somewhere. Nobody is sure which file is current, and sorting by name doesn't help, because the names were never written to be sorted.

A few naming rules fix both problems. They need no software, only agreement on the order of things.

TL;DR: Start with the date as YYYY-MM-DD, use two digits for months and days, use v1 and v2 instead of "final", and keep the order date_content_version.

The problem with casual month numbers

Name monthly files the casual way, starting with the month as a plain number ("9 sales report", "10 sales report" and so on), then sort by name. The order comes out as 10, 11, 8, 9. Names are compared character by character, so "1" comes before "8" no matter what follows it.

This was checked by sorting the names in Excel for the web. With the date first, as 2026-08, 2026-09, 2026-10, 2026-11, the same sort comes out in date order.

The four rules

  1. Date first, as year-month-day. Example: 2026-10-01_sales-report.xlsx. Sorting by name now sorts by date.
  2. Two digits for months and days. 2026-09, not 2026-9. Without the leading zero, September lands after October and November.
  3. Version numbers instead of "final". sales-report_v1, then sales-report_v2. The highest number is the latest, and nobody has to invent a second "final".
  4. A fixed order: date, content, version. Example: 2026-10-01_sales-report_v2.xlsx. When the whole team uses the same order, everyone finds files the same way.

When to bother

Any folder more than one person touches, and any folder you'll be searching six months from now. Reports, invoices, meeting notes and exports benefit most, because they arrive in a series.

Common mistakes

  • Mixing formats. A folder with half "2026-10-01" and half "Oct 1" sorts into two separate groups. Pick one format and rename the old files once.
  • Putting the date in the middle. sales-report_2026-10-01 groups by content first. That's fine if it's what you want, but it won't give you a timeline.
  • Versions past nine. If you expect more than nine versions, v01 to v10 keeps them in order.

Why developers already do this

It's the same reason ISO 8601 dates are standard in logs and backups. A string sort and a date sort agree when the date is written largest unit first with fixed widths. In Python, datetime.date.today().isoformat() gives you a string like 2026-10-01, ready to prefix a filename, and sorted() on those names returns them in date order with no parsing.


This post was written with AI assistance. The sorting example was checked in Excel for the web.

Top comments (0)