...

View Full Version : Sort Date



jeffsal
08-19-2005, 08:24 PM
This sort function does not seem to work with my date format which is
1/01/2004 no leading 0 for month. Is there anything that could be
changed so it would sort properly. It is part of a Table Sort script
(sorttable.js) Thanks


function ts_sort_date(a,b) {
// y2k notes: two digit years less than 50 are treated as 20XX,
greater than 50 are treated as 19XX
aa = ts_getInnerText(a.cells[SORT_C*OLUMN_INDEX]);
bb = ts_getInnerText(b.cells[SORT_C*OLUMN_INDEX]);
if (aa.length == 10) {
dt1 = aa.substr(6,4)+aa.substr(3,2)+*aa.substr(0,2);
} else {
yr = aa.substr(6,2);
if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
dt1 = yr+aa.substr(3,2)+aa.substr(0,*2);
}
if (bb.length == 10) {
dt2 = bb.substr(6,4)+bb.substr(3,2)+*bb.substr(0,2);
} else {
yr = bb.substr(6,2);
if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; }
dt2 = yr+bb.substr(3,2)+bb.substr(0,*2);
}
if (dt1==dt2) return 0;
if (dt1<dt2) return -1;
return 1;

SpirtOfGrandeur
08-19-2005, 09:12 PM
Convert them to dates


aDate = new Date(aa);

Then test them. Right now you are doing a string test.

jeffsal
08-19-2005, 09:20 PM
Thanks for your reply but I'm not sure what to do with the code. I'm not a javascript guy but really need to get this to work. Any help would be appreciated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum