Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7954709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:30:47+00:00 2026-06-04T03:30:47+00:00

Possible Duplicate: Javascript date sorting by convert the string in to date format I

  • 0

Possible Duplicate:
Javascript date sorting by convert the string in to date format

I am not good in jquery so I was wondering if there is a way or plugin I can use to sort date divs. I have date in YYYY:MM:DD HH:MM:SS format. I am displaying date in divs as shown below. Divs are in unordered format and I want to sort them on latest date first basis.

<div id="dateDiv">2012-04-15 10:25:45</div>
<div id="dateDiv">2012-04-10 19:41:08</div>
<div id="dateDiv">2012-04-20 07:00:10</div>
<div id="dateDiv">2012-04-12 16:45:50</div>

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:30:49+00:00Added an answer on June 4, 2026 at 3:30 am

    I don’t know much about plugins…although if you want a light weight method without plugins, you may try this:

    html:

    <div id="D">
        <div class="dateDiv">2012-04-15 10:25:45</div>
        <div class="dateDiv">2012-04-10 19:41:08</div>
        <div class="dateDiv">2012-04-20 07:00:10</div>
        <div class="dateDiv">2012-04-12 16:45:50</div>
    </div>
    

    For js:

    var elems = $.makeArray($(".dateDiv"));
    elems.sort(function(a, b) {
        return new Date( $(a).text() ) < new Date( $(b).text() );
    });
    $("#D").html(elems);
    

    UPDATE:
    Thanks to CMS for answering this question about parsing dates: Why does Date.parse give incorrect results?

    function parseDate(input) {
      var parts = input.match(/(\d+)/g);
      // new Date(year, month [, date [, hours[, minutes[, seconds[, ms]]]]])
      return new Date(parts[0], parts[1]-1, parts[2], parts[3], parts[4], parts[5]); //     months are 0-based
    }
    
    var elems = $.makeArray($(".dateDiv"));
    elems.sort(function(a, b) {
        console.log( parseDate( $(a).text() ) );
        return parseDate( $(a).text() ) < parseDate( $(b).text() );
    });
    $("#D").html(elems);​
    

    Now, don’t tell me this doesn’t work…hehe

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: javascript (jquery) calendar plugin I am going to develop the weekly calendar
Possible Duplicate: JavaScript: string contains Jquery: How to see if string contains substring In
Possible Duplicate: Convert a Unix timestamp to time in Javascript I am getting date
Possible Duplicate: Javascript callback when IFRAME is finished loading? Is there any way to
Possible Duplicate: Javascript date regex DD/MM/YYYY i'm using this validation :- jquery validation engine
Possible Duplicate: Detecting an “invalid date” Date instance in JavaScript Is there is a
Possible Duplicate: javascript: pause setTimeout(); Im using jQuery and working on a notification system
Possible Duplicate: Workarounds for JavaScript parseInt octal bug I'm parsing a string to check
Possible Duplicate: JavaScript replace all / with \ in a string? I have a
Possible Duplicate: javascript WYSIWYG HTML editors? Im not quite sure how to put this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.