Videos
I have been doing PHP and MySQL for 15+ years and have always used YYYY-MM-DD for any dates that are going to be stored or processed. I have started learning javascript, but haven't worked much with dates. I am currently working on an Oracle class and it is usually using MM-DD-YYYY.
I'm just wondering if there is a preferred date format to use across languages and platforms? Is there a particular reason why one format might be preferable to others?
For what it's worth, YYYY-MM-DD is what I always saw in my PHP training, and it's also the most logical format (in my opinion) to use for file naming.
This way, the dates can easily be sorted as strings using the default sorting rules (i.e. lexicographical sorting).
This is also why both month and day are specified using two digits (adding a leading zero if needed).
In fact it is one of the date formats defined by ISO 8601. That standard also defines a date-and-time format, 2015-03-27T15:26:40Z, which is also sortable as strings.
However, YYYYMMDD has an added benefit of making it possible to easily (no substrings or character replacements involved) parse the string as an integer, and still use default ordering on integers.
Not mentioned yet, but you quickly gloss over the order inside YYYY. That's already millennia, centuries, decades, years. That is to say, YYYY is already ordered from longest period to shortest period. The same goes for MM and DD, that's just how the number system works.
So to keep the order between fields consistent with the order within fields, the only option is YYYYMMDD.
As zahbaz and Arseni Mourzenko noted, the YYYYMMDD formats sorts easily. That is not a lucky coincidence, that's a direct consequence of putting the fields for the longest duration first (and keeping the length fixed; we are introducing a Y10K problem here.)