If you’re writing dates this way:
Jan 12th 2010 – you’re living in the past, and you’re doing it wrong.
12/01/2010 – you’re American and you’re doing it wrong.
1263298212 – you’re a machine, why are you reading my blog?
2010-01-12 – you’re ISO 8601 compliant ✅.
ISO 8601 is the standard for date writing. There are several benefits for using this standard for date writing, so here’s a list.
Yep. Dates written in ISO 8601 are sortable by a standard string sort algorithm. No natural sort required.
From left to right, it’s written in Most-Significant to Least-Significant order.
2010 is the year, changing this by one means you’re a whole year off, so it’s the most significant part.
01 is the month, changing this by one means you’re one month off, so it’s less significant.
12 is the day, changing this by one means you’re only a day off, so it’s the least significant.
Of course the ISO 8601 standard includes time formats as well, and you can go read about those in your own time.
We’re not all American. If someone writes a date in the format
12-01-2010, we don’t know whether it’s referring to the 12th of Jan, or the 1st of December.
2010-01-12, everyone knows what we’re talking about. Because nobody ever writes dates in
YYYY-DD-MM format – that would just be inane.
It Uses Safe Separators
If you use a slash / to separate the date fields, you need to escape those if you want to use them in a filename, or in a URL.
Whereas if you use the dash – character, there’s no escaping required.
It’s Language Agnostic
If you use Month names in the date, such as ‘Jan’, ‘Feb’, etc. Then the dates should be translated when you’re using them on i18n‘d sites.
Because different languages have different names for the months of the year. Duh.
But if you use ISO 8601, there’s no need for the translation, because numbers don’t usually need translating.
Huzzah! Now go fix your broken date output formats. 👋