mamatha
10-15-2008, 09:39 AM
Can anyone help me in writting javascript to display the list of dates in the descending order?
|
||||
dates in descending ordermamatha 10-15-2008, 09:39 AM Can anyone help me in writting javascript to display the list of dates in the descending order? carlitos_way 10-15-2008, 10:52 AM Can anyone help me in writting javascript to display the list of dates in the descending order? can you explain yourself better? are these dates in a form? Are they in a array? mamatha 10-15-2008, 11:45 AM can you explain yourself better? are these dates in a form? Are they in a array? I want to know how to write a javascript "to sort a set of date and time in the ascending order" that is i am having 5 to 6 date&time values from the external application in the format "yyyy-mm-dd hh:mm:ss" and i want to write a function to display them in the ascending order using jscript. The dates are in a form. Philip M 10-15-2008, 11:53 AM Sounds like a homework asignment. First you specifed descending, then ascending order. So which is it? Have a look at the JavaScript sort() method. rnd me 10-15-2008, 07:46 PM var dates = [ "2002-05-11 05:12:43", "1999-06-01 11:01:13", "2003-02-24 10:10:33", "2001-05-12 03:11:26" ] var dates2=[]; for(var i=0, mx = dates.length; i<mx;i++){ var p = dates[i].split(/\D+/g); dates2[i]= new Date(p[0],p[1],p[2],p[3],p[4],p[5]); } //ascending: alert(dates2.sort(function(a,b){return a-b}).join("\n")) //descending: alert(dates2.sort(function(a,b){return b-a}).join("\n")) |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum