SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    singapore
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to sort date using JavaScript?

    Date format:
    2003/03/15 04:00
    2003/12/13 12:00
    2004/02/12 13:12
    2001/04/22 21:24

    How can I sort all this date by the latest using JavaScript?
    Last edited by chocolategal; Sep 19, 2004 at 20:19.

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var dates = [
    	"2003/03/15 04:00",
    	"2003/12/13 12:00",
    	"2004/02/12 13:12",
    	"2001/04/22 21:24"
    ];
    
    dates.sort(function(a, b) {
    	return Date.parse(a) - Date.parse(b);
    });
    
    alert(dates.join("\n"));


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •