For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2005 > Sort Date









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Sort Date
jeffsal@charter.net

2005-08-19, 4:20 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_COLUMN_INDEX]);
bb = ts_getInnerText(b.cells[SORT_COLUMN_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;

Andrew Thompson

2005-08-19, 4:20 pm

On 19 Aug 2005 10:21:01 -0700, jeffsal@charter.net wrote:

> 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) ...


You have the wrong group, I'm afraid..
<http://www.physci.org/codes/javafaq.jsp#js>

--
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"You can blow out a candle, but you can't blow out a fire. Once the flame
begin to catch, the wind will blow it higher."
Peter Gabriel 'Biko'
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com