House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Community (CF-Community)

Javascript date sorting

  << Previous Post |  RSS |  Tree View |  Sort Oldest First |  Subscribe to this Group Next >> 

Javascript date sorting

Matthew Small wrote: Jochem van Dieten 05/17/2005 10:31 AM
I'm working on this now for something. Jim Davis 05/17/2005 10:21 AM
You'll need to use a little more processing to change the AM/PM into a Matthew Small 05/17/2005 09:16 AM
G wrote: Jochem van Dieten 05/17/2005 08:52 AM
Oops, that should be 20051235 of course, not 20051335. G 05/17/2005 08:49 AM
----- Excess quoted text cut - see Original Post for more ----- G 05/17/2005 08:46 AM
G wrote: Jochem van Dieten 05/17/2005 08:34 AM
Can you work with the dates in military time? G 05/17/2005 08:14 AM
I need to sort an array of strings in the format "05/17/2005 01:33 AM" by date Jochem van Dieten 05/17/2005 06:47 AM

05/17/2005 10:31 AM
Author: Jochem van Dieten Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157883 Matthew Small wrote: ----- Excess quoted text cut - see Original Post for more ----- That almost worked, just needed to get the val() right and switch some substring positions. Thanx. Jochem
05/17/2005 10:21 AM
Author: Jim Davis Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157879 I'm working on this now for something. Personally I think it's a mistake to treat the dates as strings - first convert them to dates, then your job will be easier. It may be as simple as this: var d=new Date("05/17/2005 01:33 AM") If the string doesn't parse correctly (if JavaScript doesn't recognize the date format) a regex could be used to convert it to a date format that Javascript does recognize. To actually deal with the objects I'm using my obCollectionOrdered component.  It's available here: http://www.depressedpress.com/depressedpress/Content/Development/JavaScript/ Extensions/ObCollectionOrdered/Index.cfm Once I have the dates I you could do a simple sort function and pass it to the sort method.  I actually create a new property of the date object containing the value of Date.parse() (a numeric representation of the date). I can then use the "SortByProp()" method of my collection component to sort the dates (both ascending and descending).  It's insanely simple after that to display the dates (in any format you like) by looping over the collection. Works a treat. Jim Davis
05/17/2005 09:16 AM
Author: Matthew Small Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157864 You'll need to use a little more processing to change the AM/PM into a military system. Something to the effect of: function DateTimeOrderFormat (dt) {   hr = dt.substr(14,2);   if(hr == "12"){hr = "00";}   if (dt.substr(11,2) == "PM") {hr = val(hr) + 12;}   return dt.substr(6,4)+dt.substr(0,2)+dt.substr(3,2)+hr+ bb.substr(14,2); } - Matt Small G wrote: > > No need to include A's and P's once yer in military time....your sorting > would then be based on straight 00-24. But I don't have it in 24 hour time. I have a piece of HTML that I extract strings from and the strings are formatted like "05/17/2005 01:33 AM". Jochem
05/17/2005 08:52 AM
Author: Jochem van Dieten Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157860 G wrote: > > No need to include A's and P's once yer in military time....your sorting > would then be based on straight 00-24. But I don't have it in 24 hour time. I have a piece of HTML that I extract strings from and the strings are formatted like "05/17/2005 01:33 AM". Jochem
05/17/2005 08:49 AM
Author: G Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157858 Oops, that should be 20051235 of course, not 20051335. I hate Tuesdays. > > For "12:35AM" you'd have: 20050035 > For "12:35PM" you'd have: 20051335 > > No need to include A's and P's once yer in military time....your sorting > would then be based on straight 00-24. >
05/17/2005 08:46 AM
Author: G Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157857 ----- Excess quoted text cut - see Original Post for more ----- Why? For "12:35AM" you'd have: 20050035 For "12:35PM" you'd have: 20051335 No need to include A's and P's once yer in military time....your sorting would then be based on straight 00-24.
05/17/2005 08:34 AM
Author: Jochem van Dieten Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157856 G wrote: > Can you work with the dates in military time? I wish I could, that would be easy. But this is for a Greasemonkey script so I have to work with the format that is available (unless Michael wants to change the HoF archives to 24 hour times). I could of course add something to produce 20051305A0900 vs 20051305P0900 but that doesn't work quite right with times like 12:35 AM. Jochem
05/17/2005 08:14 AM
Author: G Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157855 Can you work with the dates in military time? > > How do I get proper AM/PM parsing into this? > > Jochem >
05/17/2005 06:47 AM
Author: Jochem van Dieten Short Link: http://www.houseoffusion.com/groups/cf-community/thread.cfm/threadid:17191#157844 I need to sort an array of strings in the format "05/17/2005 01:33 AM" by date using javascript. For that I need a custom sort function. What I have so far is: function sortTable() {   sortfn = mysort;   var newRows = new Array();   for (j=1;j<newIndex.rows.length;j++) newRows[j-1] = newIndex.rows[j];   newRows.sort(mysort); } function mysort(a,b) {   aa = a.cells[2].firstChild.innerHTML;   bb = b.cells[2].firstChild.innerHTML;   dt1 = aa.substr(6,4)+aa.substr(0,2)+aa.substr(3,2)+aa.substr(11,2)+aa.substr(14,2);   dt2 = bb.substr(6,4)+bb.substr(0,2)+bb.substr(3,2)+bb.substr(11,2)+bb.substr(14,2);   if (dt1==dt2) return 0;   if (dt1>dt2) return -1;   return 1; }; How do I get proper AM/PM parsing into this? Jochem
<< Previous Thread Today's Threads Next Thread >>

Search cf-community

May 17, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference