I hate having to convert between dates and times. I hate date calculations (stupid leap year). I even hate date formatting (why must every client have their own preferred format?). Dates are just plain messy.
ISO 8601 (a.k.a. YYYY-MM-DD) eases the mess.
Quick question: what day of the month are the following dates representing?
- 2009-01-09 20:18:53
- Mar 2, 2009
Follow up question: how would you sort dates in each format? For either #3 or #4, you first need to convert to an internal date representation before comparing. Either #1 or #2 can be compared with no conversion. The string "2009-01-09 20:18:53" is less than "2009-02-08 00:12:30":
if ("2009-01-09 20:18:53" < "2009-02-08 00:12:30") alert("yup");Hell, it even works in fake languages like XSL1.
Another important benefit of ISO 8601 is its ease of conversion to native date format—simply split on dashes. This makes it ideal for a simple yet robust data interchange format.
So format #1 (ISO 8601) is easiest for human readability while still making for simple comparisons and conversions. Ease and simplicity always trump any other concerns.
Ease and simplicity == fewer bugs.
Ease and simplicity == more maintainable code.
I am not arguing that dates should be ISO 8601 no matter what. In the final UI, go with whatever localizes best. But until design aesthetics become significant, ISO 8601 is the format.
Client wants mm/dd/yyyy in a CSV dump? Tough. It lacks readability and can not be easily compared.
Want to save space in a DB string field by dropping the dashes? Wrong. It lacks readability.
Think sticking with the application default of Mon D, YYYY is good for consistency? Consistency, when adding complexity, is the bane of application development.
Always strive for simplicity, for maintainability. In 6 months, which is the easiest for you or another developer to grok? Which is the least likely to cause bugs down the line?
IS0 8601 is the cleanser for life's messy dates.
1 Just because I have this lying about, in XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:sort select="date" order="descending"/>