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 7016255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:45:38+00:00 2026-05-27T22:45:38+00:00

I have a datatable I’m using which has 5 columns ( http://datatables.net/ ) The

  • 0

I have a datatable I’m using which has 5 columns ( http://datatables.net/ )

The columns are

  1. Date in format of: Jan 5
  2. Time in format of: 10:31 AM (xx:xx XX)
  3. Columns 3, 4, 5 aren’t important, they’re just data that I dont care about the sorting as long as 1 & 2 are correct.

I want to sort by Date FIRST (most recent), then I want to sort by Time (most recent at top).

So Jan 5, 4:58 PM should show before 4:58 AM, and obviously all the other numbers need to work as well for all other times. The format is always the same, ie: 12:34 AM, 4:15 PM, 12:00 AM, etc.

For the date, that already works perfectly. There’s only 2 days of data max in the datatable, so even when it rolls over to the 1st of the month, that will still show at the top which is fine. I have looked at the documentation and I’m confused how to do the correct sorting for my Time column.

Here is my code:

oTable = $('#posts').dataTable({
    "bSort": true,
    "aaSorting": [ [0,'desc'], [1,'asc'] ],
    "aoColumns": [
                null,
                { "sType": 'time-sort' },
                null,
                null,
                null
           ]

});

This is from here: http://datatables.net/release-datatables/examples/basic_init/multi_col_sort.html

I take it now I have to build some sort of custom sorting algorithm for time using the sType property for “aoColumns” (you can see it in the example link above where he sorts case sensitively), and I have zero idea how to do this 🙁 I’m not quite even sure if I did this right so far. It seems to sort the two columns fine, but now I need to make it so time is proper…

Here is the other part of the code that I believe I need. (once again, this is from the example). I’m 99% sure this is where I need to put in my custom time sorting code for both ascending and decending.

/* Define two custom functions (asc and desc) for time sorting */
jQuery.fn.dataTableExt.oSort['time-sort-asc']  = function(x,y) {
    return ???;
};

jQuery.fn.dataTableExt.oSort['time-sort-desc'] = function(x,y) {
    return ???
};
  • 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-05-27T22:45:39+00:00Added an answer on May 27, 2026 at 10:45 pm

    You can do this by parsing the time from your input string into a date object and then comparing the date objects:

    Working Demo here: http://live.datatables.net/erefom/2/edit#preview

    Source here: http://live.datatables.net/erefom/2/edit

    Also see this answer: What is the best way to parse a time into a Date object from user input in Javascript?

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

Sidebar

Related Questions

I have a DataTable which is bound to DataGridView . DataTable has several columns
I have a DataTable which has 10 columns, and after I add some rows
I have a datatable that has a date column, but I am stumped as
I have datatable in vb.net 2008 has 40000 rows. i want to delete 1000
I have DataTable with the following columns: ClientID date numberOfTransactions price ClientID is of
I have a DataTable which has a column amount for each rows and I'd
I'm using ICEFaces. I have datatable with multiple columns. One I load the page
I have a DataTable which has the following structure. StartDate (Type DateTime) EndDate (Type
I have one datatable which has DataTable: SeqNo ItemID ItemName ------- ------ -------- 1
I have a datatable with few rows each row has few columns. I want

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.