• Jon (unregistered)

    My favorite never ending pet project is to write a parser that picks out and parses all dates from some random text, e.g. a web page. Of course I don't expect it to find and parse all correctly, but it is like a competition between a lot of candidates. A part of the project is to come up with some regex extensions suitable for the task.

    (Current state is that the project becomes my Moriarty and I am close to Reichenbach Falls.)

  • Norman Diamond (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    Japan almost gets it right.
    Along with China (both of them) and some other countries.
    ¯\(°_o)/¯ I DUNNO LOL:
    Apparently they prefer to use YYYY/MM/DD (with slashes rather than dashes) when they aren't using YYYY年M月D日.
    I've only seen it with slashes in Microsoft stuff. Dashes or periods are more common in handwriting and non-Microsoft stuff, but 年月日 is still most common in printed materials and web sites.
    ¯\(°_o)/¯ I DUNNO LOL:
    At least they've mostly stopped using imperial years.
    They mostly HAVEN'T stopped in most formal stuff like tax returns, health insurance cards, dates on coins, etc.
  • Norman Diamond (unregistered) in reply to Dvorak The Explorer
    Dvorak The Explorer:
    Taiwan: YYYY年M月D日
    That reminds me: Did Taiwan have trouble with the Y1H problem?
  • Bill C. (unregistered) in reply to College Student
    College Student:
    I do not understand why anyone would attempt to interact with dates in any other way.
    When you really get to be a college student you'll learn why.
  • (cs)

    In the summer of 1997 I converted all our software, both input and output, to yyyy/mm/dd. This was in Thailand. Many users complained. I explained that it was necessary for Y2K. They'd all heard of that, so they accepted my changes.

    Three years later, I left it that way because I prefer it to the variable mess humans write for dates. Everyone had forgotten the past formats and were used to seeing my better format by that time (for example, it sorts as a string).

    As of 2014/04/10 they are STILL using it.

  • B2382F29 (unregistered)

    The real WTF is the stupid way people are able to actually make an easy standard confusing again.

    If you want to use the stupid US-WTF-order (MM/DD/YY) then please use the slashes only. BUT by using dashes (like in the ISO standard (YYYY-MM-DD)) in combination with the fucked up order you are just confusing everyone.

  • Norman Diamond (unregistered) in reply to AndyCanfield
    AndyCanfield:
    In the summer of 1997 I converted all our software, both input and output, to yyyy/mm/dd. This was in Thailand. Many users complained. I explained that it was necessary for Y2K. They'd all heard of that, so they accepted my changes.
    What? Didn't Thailand go through Y2K a few hundred years ago?
  • (cs) in reply to herby
    herby:
    Hopefully they don't enter April 31 or February 30, but flinging an error will solve that.
    Sherman, set the WABAC machine for the day before the first of March, 1712. The place? Sweden.

    So they arrive, and what is the local date?

    February 30...

    http://en.wikipedia.org/wiki/February_30

  • Maj najm (unregistered) in reply to ¯\(°_o)/¯ I DUNNO LOL
    ¯\(°_o)/¯ I DUNNO LOL:
    RandomGuy:
    Of course TRWTF is M/D/Y convention, even worse is MM-DD-YY. Obligatory xkcd-reference: http://www.xkcd.com/1179/
    Japan almost gets it right. Apparently they prefer to use YYYY/MM/DD (with slashes rather than dashes) when they aren't using YYYY年M月D日. Sometimes it's even YYYY/M/D. At least they've mostly stopped using imperial years.
    Sweden gets it mostly right... We use 20140410, 2014-04-10, 140410 or 14-04-10. The hyphenated form seems to have gotten more common the last decade.
  • modo (unregistered) in reply to QJo
    QJo:
    TRWTF, of course, is the Java calendar / date system, in which the months go from 0 to 11. Catches me out every time, that does.
    Gotta give way for Undecimber.
  • (cs) in reply to anonymous
    anonymous:
    Screw you yankees! Choose either little or big endian, not bittle endian!

    Unless you use yyyy-mm-dd, then shut up. :-) If you do, then carry on with your rage. If you use anything with the year after the month and date then that's just as bittle endian when you add the time.

  • (cs)

    i am tried of seeing articles that have date formatting issue. treat date as dates and not as string or numbers.

  • CigarDoug (unregistered) in reply to RandomGuy
    RandomGuy:
    Of course TRWTF is M/D/Y convention, even worse is MM-DD-YY. Obligatory xkcd-reference: http://www.xkcd.com/1179/
    If you ask an American what day it is, most of us would say, "April 10th, 2014". Hence 4/10/2014. It's not any more complicated than that.

    Don't be hating on our dating.

  • (cs) in reply to Ven I Am
    Ven I Am:
    College Student:
    All applications I write that require datetime input with a date picker or calendar widget. I do not understand why anyone would attempt to interact with dates in any other way.
    You obviously didn't write Excel then.

    Double the trouble and trouble the Double.

  • (cs) in reply to QJo
    QJo:
    chubertdev:
    kjordan2001:
    What are you doing with dates to make that happen in JavaScript? Are you running them through an eval or something?

    I was wondering the same thing.

    alert('2013-02-27');

    Message from webpage 2013-02-27

    Hmm... something's going wrong then, and it's non-trivial. Let me go and check my codebase again ... we could have implemented a WTF.

    Do you mind posting a snippet with this code?

  • (cs)

    Never forget 9/11............../1752

  • David Mårtensson (unregistered) in reply to OldPeter
    OldPeter:
    David Mårtensson:
    Indifferent:
    Sometimes I wonder why date conversion/formatting seems to be such a special case for special cases

    Simply because Dates follows very few set rules.

    The calendar has changed over the centuries and different ways to write dates, which in same cases are syntactically identical but where the different numbers represent different date parts depending on in which locale you run the code, makes date handling a chore.

    I remember 10 years ago I designed a simple cargo tracking application for an import company.

    The shipping office filled in shipping info and the local office verified it on reception.

    Despite being within the same company we found out they wrote the dates in 5 different ways :P.

    We ended up adding a date picker to prevent them from entering the wrong format.

    This. And then be aware that the same is valid for countries. You must not identify a certain country with one format, there can occur multiple formats in use in the same country. So always let the user choose a date format, don't rely on his country setting/choice.

    Thats why I wrote locale and not country ;)

    But we ended up not letting them choose format at all, we opened a calendar popup where they could click the right date and then no more broken dates.

  • Peter Wolff (unregistered) in reply to modo

    Starting to number the month with 0 (and the day of the month too), is the only logical way to do it.

    This logic is the reason we use times from 00:00:00 to 23:59:59.

    (By the way, any code monkey should be more than familiar with the idea that the FIRST element of an array (we say FIRST, SECOND, etc day. of month, and FIRST, SECOND, etc. month of the year after all) has the index (or number) ZERO.

    So TRWTF is our (the humans) custom to number months and days with an offset of one.

  • (cs) in reply to Peter Wolff
    Peter Wolff:
    Starting to number the month with 0 (and the day of the month too), is the only logical way to do it.

    This logic is the reason we use times from 00:00:00 to 23:59:59.

    (By the way, any code monkey should be more than familiar with the idea that the FIRST element of an array (we say FIRST, SECOND, etc day. of month, and FIRST, SECOND, etc. month of the year after all) has the index (or number) ZERO.

    So TRWTF is our (the humans) custom to number months and days with an offset of one.

    Yeah, I dealt with that last night/early this morning.

    Had a DB where month was stored as 0-11, but the datetime constructor in Python uses 1-12. Fun.

  • Neil (unregistered) in reply to QJo
    QJo:
    The trouble is with the format 2013-02-27 is that when you build such a string in Javascript it evaluates it as a mathematical expression and you get (for the above instance) 1984.
    SQLBase, a database that I once used, recognises the following literal date formats:

    dd-mon-yyyy dd-mon-yy dd/mon/yyyy dd/mon/yy mm/dd/yy mm-dd-yy mm-dd-yyyy dd-mm-yy yyyy-mm-dd

    In those rare cases where I had to use literals I would use the yyyy-mm-dd syntax to avoid confusion. I don't know how it decided that this wasn't a subtraction operation.

  • lmm (unregistered) in reply to Peter Wolff
    Peter Wolff:
    Starting to number the month with 0 (and the day of the month too), is the only logical way to do it.

    This logic is the reason we use times from 00:00:00 to 23:59:59.

    (By the way, any code monkey should be more than familiar with the idea that the FIRST element of an array (we say FIRST, SECOND, etc day. of month, and FIRST, SECOND, etc. month of the year after all) has the index (or number) ZERO.

    So TRWTF is our (the humans) custom to number months and days with an offset of one.

    I'd be fine with that except the Java API uses 1 for the first day of the month, and 1 for the first year. For months, consistency with year/day is more important than consistency with time.

  • polk (unregistered)

    typically of Java programmers

  • Best Practices (unregistered)

    The problem is clearly that the += operator is used to concatenate onto the dateString. Best practices clearly call for the use of StringBuilder in such performance-sensitive applications including repeated string concatenation and exception-handling code.

  • Per Kjellberg (unregistered)

    Interesting discussion ! I think that one of the most compelling reasons to use YYYY-MM-DD is that it cannot be confused with anything else. Another benefit is that files are automatically sorted in the correct order.

Leave a comment on “Exceptional Date Formatting”

Log In or post as a guest

Replying to comment #:

« Return to Article