in reply to Re: sort based on date
in thread sort based on date

Unless you know all the dates in the set are from the same year.

Replies are listed 'Best First'.
Re^3: sort based on date
by aquarium (Curate) on Aug 09, 2010 at 01:22 UTC
    Put another way: unless you get the year into your dates, the year will get you just after new year.
    Also, POSIX or equivalent ISO date format YYYY/MM/DD hh:mm:ss is the most portable and most universally understood (human or program), and also best defined for sorting or other date manipulations.
    the hardest line to type correctly is: stty erase ^H
      Put another way: unless you get the year into your dates, the year will get you just after new year.

      Put another way: If the data already exists and is already segregated by year...

      Also, POSIX or equivalent ISO date format YYYY/MM/DD hh:mm:ss is the most portable and most universally understood (human or program), and also best defined for sorting or other date manipulations.

      That's all well and good for data you control the source of, but often you don't. You have to make do with what is, not with what you might like it to be. That's the real world.

      Excuse me. Could you give me directions to Tipperary?

      Ah now. If I were going there, I wouldn't be starting from here!

Re^3: sort based on date
by JavaFan (Canon) on Aug 09, 2010 at 10:50 UTC
    Unless you know all the dates in the set are from the same year.
    Sure, but no such assumption was stated by the OP. An equally valid assumption would be "next occurrence" of the given dates - one might for instance have to order dates for soccer matches of the coming season.

    My meta point of course is that if people post problems here, they shouldn't hide essential knowledge about the problem (I do assume the OP knows which years the dates are supposed to have).

      Sure, but no such assumption was stated by the OP.

      Perhaps he thought, given the absence of year information in the sample data, the assumption was too obvious to state.

      (I do assume the OP knows which years the dates are supposed to have).

      I assume OPs to know their problem space. They sometimes prove me wrong, but the alternative of every SoPWer being required to fully delineate every possible constraint and nuance of their problems, would severely detract from concise and lucid questions.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      JavaFan, you are right.

      My date contains only one year.
      It wont include Aug 2009 and Aug 2010 at the same time.
      The script search through a log file for last 6 months period.


      ~suhail
        Your example contains a January date, which is more than 6 month ago.

        Note also that for half a year, the previous 6 months will contain dates from more than one year. I presume that if you're running your program in March, you'd want December dates to be sorted before January dates, don't you?