0

http://pastie.org/private/y97y0idv0s4z3grztqsgw

Here is my Json response, how can i sort this based on DateOfBirth... i mean the result...

John Cooper
  • 7,343
  • 31
  • 80
  • 100
  • Here is a similar question look if it helps. http://stackoverflow.com/questions/979256/how-to-sort-a-json-array – Shadow Aug 09 '11 at 08:49
  • Please try and make the question at least make sense without the external link. If the code is too long to put in the question, chances are it's going to be too long for a prospective answerer to read. – Tim Down Aug 09 '11 at 09:51

3 Answers3

1

What kind of date format is: \Date(410225400000-0500)/ ????

You will need to parse that into a normal date format to do comparisons.

You seem to be storing time as well?

Easiest is to store either unixtime or juliandate, both sort nicely. But yyyymmdd works fine too. But the string you have does not.

Ariel
  • 25,995
  • 5
  • 59
  • 69
0

I think it's best to convert the string-value from DateOfBirth to a real date. Given the format of the datestring in your json, this may be a way to do the sorting then:

var sortList = Json.sort( function(a,b) {
        var dateA = new Date(Number(a.DateOfBirth.replace(/[^0-9]/g,''))),
            dateB = new Date(Number(b.DateOfBirth.replace(/[^0-9]/g,'')));
        return dateA < b.dateB;
});
KooiInc
  • 119,216
  • 31
  • 141
  • 177
0

A possible solution is to sort the date using a space-filling-curve. It's a fractal function f(x,y)=z in the euklidean space. Look here: http://lapin-bleu.net/riviera/?p=78

Micromega
  • 12,486
  • 7
  • 35
  • 72