Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

24
  • 91
    @lucaswxp: If you write a special-case comparison for strings following a specific schema, you can of course make it as baroque as you want. The thing here is that the schema is designed such that lexical order (as well as lexical number-aware order) is also logical order, so no need for customizing. Commented Sep 25, 2018 at 0:48
  • 19
    @lucaswxp Your date string might not be in memory. Practical example: You have a csv file already sorted by ISO date and millions+ of rows per year. And you want to return only the rows between certain dates. You can read the file line by line (row by row) until you reach your first date, then load rows into memory until you reach your last date. You can skip the rest of the file. But if you save the date as some other format, or sorted by year only, you would have to read trough the entire year worth of records before closing the file. Commented Sep 25, 2018 at 5:00
  • 49
    Note that the dashes are optional in ISO 8601, so YYYYMMDD is ISO 8601. Commented Sep 25, 2018 at 11:14
  • 33
    @Benoit A proposal has already been made to solve the Y10K problem. If we're still using the same era then, we'll go to AYYYYYMMDD until Y100K, which will be BYYYYYYMMDD, CYYYYYYYMMDD, DYYYYYYYYMMDD, EYYYYYYYYYMMDD. This leading alpha prefix assures correct sort order (provided that "A0YYYY..." etc. are invalid representations if any YYYY... dates are still used). At some point when the number of year digits are divisible by three, we'll start adding three digits each time we change alpha prefix, in order to assure we don't run out of letters before the heat death of the universe. Commented Sep 25, 2018 at 15:00
  • 35
    It's important to note that with this format, sorting isn't just "easier." The lexical (character based) sort becomes equivalent to the temporal sort, which means you can sort temporally without parsing. Commented Sep 25, 2018 at 15:39