HighDots Forums  

Sort Date

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Sort Date in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jeffsal
 
Posts: n/a

Default Sort Date - 08-19-2005 , 12:27 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;


Reply With Quote
  #2  
Old   
Jasen Betts
 
Posts: n/a

Default Re: Sort Date - 10-15-2005 , 07:35 AM






On 2005-08-19, jeffsal <jeffsal (AT) charter (DOT) net> wrote:
Quote:
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
break the date into numbers not substrings.



--

Bye.
Jasen


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.