|
|
Home / Groups / ColdFusion Community (CF-Community)
Javascript date sortingI'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 |
Mailing Lists
|
Latest Fusion Authority Articles
|