I’m needing some help to sort my data array by a timestamp field …..
I have a 2D array “AvatarArr” populated with data from a remote source, but it is basically “Name1, Login Timestamp1, Logout Timestamp1, Location1,Name2, Login Timestamp2…..etc”
I also have the following sort functions defined..
[CODE]function byName (a, b) {return a[0] == b[0] ? 0 : a[0] < b[0] ? -1 : 1}
function byLogin (a, b) {return a[1] == b[1] ? 0 : a[1] < b[1] ? -1 : 1}
function byLogout (a, b) {return a[2] == b[2] ? 0 : a[2] < b[2] ? -1 : 1}
function byLocation (a, b) {return a[3] == b[3] ? 0 : a[3] < b[3] ? -1 : 1}
So when I populate my table with data I can sort the table by any column, for example to sort by name I call
[CODE]AvatarArr.sort(byName);
Now this works EXCEPT my Timestamp data isn’t in a format that makes it easy to sort.
The timestamp comes in as
[QUOTE]
Mon 10/26/2009 at 2:05 am
for example.
Is there a trick or some way of changing the function definition of byLogin to handle sorting a timestamp like this correctly (by date/time) rather than what currently happens which is alphabetically?
Thanks
Richard