Ordering columns with different date formats

Ordering columns with different date formats

LBigLBig Posts: 5Questions: 2Answers: 0

My data table has two columns with different date formats. I wish to be able to sort either column by date. One column is formatted as 15 Oct 08 and I use DataTable.datetime('D MMM YY'). This column will sort correctly. The other column is formatted as 10 Feb 25 15:14 and will only sort as text.
The Ordering formatted dates (Moment.js) page (https://datatables.net/examples/datetime/order-moment.html) says:
Note that the parsing is strict - your assigned format must exactly match the data.
How can I sort the two columns with different date formats?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,670Questions: 26Answers: 5,017
    Answer ✓

    You can supply multiple formats. Use a second DataTable.datetime(..) statement for the second format.

    Kevin

  • LBigLBig Posts: 5Questions: 2Answers: 0

    Thank you. I wasn't sure if it was possible to have two different format statements. I have now added the second one and both sorts work.

Sign In or Register to comment.