Date Formats
The basic standard date format is YYYY-MM-DD, where YYYY is the four digit year, MM is the two digit month and DD is the two digit day. This is specified by ISO-8601. The standared does describe alternatives such as omitting the hyphens but this is the basic standard. It also allows the use of a two digit year, which I disagree with. In fact, the W3C (the group responsible for web standards) seems to feel the same way. Their standard date format is similar to ISO-8601 but stricter and insists on four digits years.
Let’s discuss why a standard date format is important. Let’s use an example. 1/9/05. What date do you think this is? If you’re in the U.S. you probably would say January 9th, 2005. If you are in the U.K. you probably would say September 1st, 2005. Do you know where I’m from? If not then you have no way of knowing what I mean by 1/9/05. So it can create a lot of confusion. It gets more complicated than that but I think that is enough to make my point.
Here’s another example. I see this all the time at work. Somebody will make a copy of a spreadsheet so they can have a snapshot of it on that date. They will name it with the date code in the filename. Here’s an example of a directory of such files.
- something_030504.xls
- something_051605.xls
- something_061204.xls
- something_082304.xls
First you need to figure out what date format we are using. Since the middle set of numbers is greater than 12 in the third and fourth examples we know that that is the day. But there is no way of knowing which part is the year. Well, in this example the format is MMDDYY (Month, Day, Year). The problem with that is the most recent file is the second one in the list because the files are sorted by name. A better but still clunky solution is to use the format YY-MM-DD (Year, Month, Day). Then they are sorted correctly. It becomes a huge mess when you have multiple people creating these files and some use the MMDDYY format and others use YYMMDD. What’s the solution YYYYMMDD. The four digit year eliminates confusion between month and year. It’s still possible for someone to swap month and day but I’ve never seen anyone use the format YYYYDDMM. With YYYYMMDD you eliminate confusion and the files are sorted
correctly when sorted by name. Oh yeah, it also follows the standard. Imagine that.