// You need to test the year, year and month, or year, month and date of each item,
// sorting on the first difference found.
// parseInt is used for clients that think '08' is 10....
Code:
var days= ['11.08.2010','18.09.2010',
'23.09.2010','30.08.2010'];
days.sort(function(a, b){
var aa= a.split('.'), bb= b.split('.');
if(aa[2]!= bb[2]) return aa[2]-bb[2];
if(aa[1]!= bb[1]){
return parseInt(aa[1], 10)-parseInt(bb[1], 10);
}
return parseInt(aa[0], 10)-parseInt(bb[0], 10);
});
alert(days.join('\n'))
/* value:
11.08.2010
30.08.2010
18.09.2010
23.09.2010
*/
Bookmarks