How to write a date seems kind of trivial for a technical tip, but it is obviously needed because so many people get it wrong.

Your date format is especially important when you use it for versioning by putting it put a date at the end of your filename.

The ISO 8601 standard says that dates should be in the format yyyy-mm-dd. You can stop reading now if you promise to use this format for your dates in the future...

...still with us? You obviously need more convincing.

The two main problems with dates are ambiguity of format, and sorting/comparison.

Try to find the most recent date in this (sorted) list:

  1. 01-01-2001
  2. 01-10-2009
  3. 04-09-2009
  4. 07-01-2005
  5. 13-12-2004

Tricky? First of all, the list is sorted alphabetically, so you have to read the entire list instead of just picking the last date in the list. Secondly, the date format is ambiguous; is it using the American date format (mm-dd-yyyy) or the European date format (dd-mm-yyyy)? The last value in the list gives you a clue that it is using the European date format, where day appears first. So the most recent date is item 2 - 1st of October, 2009.

Here is the same (sorted) list, this time using the ISO 8601 format:

  1. 2001-01-01
  2. 2004-12-13
  3. 2005-01-07
  4. 2009-09-04
  5. 2009-10-01

See how much easier it is to find the correct date?

The same concept applies to code you may have to write. It is simple to use strcmp() to determine which date occurs later if the dates are in a sensible format. The same exercise becomes painful when dates are in dd-mm-yyyy or mm-dd-yyyy format. Even worse are dates that use the name of the month instead of a number.

Using a sensible date format is such an easy thing to do. If you are storing a date in a computer, please help make everyone's life (slightly) easier and use yyyy-mm-dd.

Tech tips from JDS


This article is AWESOMESAUCE in an easy pour bottle!

i’ll second that! American dates are awkward to read, it is easier to find the correct date in the second list because the list is date sorted, the first list with the correctly formatted dates isn’t date sorted it is number sorted based on the first number in the date, like the man says, ‘minutes, seconds, then hours’?

American dates are just *wrong* – kind of like reading time off in minutes, seconds, then hours.

They make no sense whatsoever!