It's well-known that different countries use different date formats. A funny thing is that the format used in the USA is even different from the format used in the UK.
- 01/02/25 means January 2nd in the USA
- 01/02/25 means the 1st of February in the UK
There is a huge list of date formats on Wikipedia. The format differences lead to obvious misunderstandings. In many countries, the slash character is used to separate years, months, and days. But the order of the fields varies. For that reason, it's impossible to differentiate between February 1st or January 2nd without knowing the country. Worse: this separator character cannot be used in file names on most computers, Windows will complain with the following message:
A file name can't contain any of the following characters: \ / : * ? " < > |
What is not well-known is that ISO 8601 has been teaching us how to format dates since 1998! That document defines a standard way to format dates. Most people didn't hear about it, even if most of us already saw those dates somewhere, on a receipt, on a website, or in a file.
The dates below are compliant with that International Standard:
- 2025-02-16
- 4 digits for the year
- 2 digits for the month
- 2 digits for the day
- 2025-02-16T05:08:15
- Same as above, with a specified time, expressed in local time
- 2025-02-16T10:18:15.394
- Same as above, with the seconds expressed with a decimal point
- There is no limit on the number of digits after the decimal point
- 2025-02-16T05:08:15Z
- The letter
Zindicates that the time is in UTC
- The letter
- 2025-02-16T14:40:00+01:00
- One can even define the timezone: here it's Paris time UTC+01:00
In essence:
- To avoid confusion, the slash separator is replaced by an hyphen
- The number of digits for elements is fixed
- Year is always composed of 4 digits
- Month is always composed of 2 digits
- Day is always composed of 2 digits
- An optional timestamp can be added
- An optional timezone can be added
Software-related notes
In most filesystems, a file has multiple properties such as a name, a creation date, an access date, and similar attributes. The creation date is not always a reliable information, as the file might have been copied across multiple computers, sent through emails or websites, and the recorded date may not be accurate. This is why photos often include additional metadata that contains the creation date. On the other hand, a file name is usually quite reliable, and we can embed the creation date in the file name.
To achieve that, one could simply use the prefix YYYY-MM-DD. The great outcome is that after sorting the files by name, the files will be grouped by year, month, day and then by name. Files from 2025 will appear after 2024, file from February will appear after January, and so on.
2025-02-22-MyFile1.docx
2025-02-23-MyFile2.docx
2025-02-24-MyFile3.docx
While it's sounds possible to manually name the files with the YYYY-MM-DD prefix, it does not sounds reasonable to manually name the files with a full ISO date. But a computer program could do that easily. We saw that digits are fixed for years, months, days and time. Because of this, the separators could be omitted. The date become less readable for an human, but can be stored in a filename.
20250218T050815Z-screenshot-in-local-time.png
20250218T144000+0100-screenshot-in-timezone.png
As of 2025, most of date software libraries will provide functions to interface with ISO dates, in JavaScript the function is named Date.toISOString:
const TimeNow = new Date().toISOString(); console.log(TimeNow); -->