Title: Unable to Sort Date
Last modified: March 2, 2019

---

# Unable to Sort Date

 *  Resolved [gtexeira](https://wordpress.org/support/users/gtexeira/)
 * (@gtexeira)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/)
 * A table is not being sorted by date in descending order, ie Most current to oldest
   date.
 * I am importing a CSV file with a date format of yyyy-mm-dd. The dates are in 
   column 1. Here is a sample:
    2018-03-18,22,2,2,3,0,0,0,1,0,0,2,32
 * I have also included the following code in the custom commands field:
 * order:[[0,’desc’]],columnDefs:[{type:’date’,targets:[0]}]
 * I also have the line checked in Use the following features of the DataTables 
   JavaScript library with this table
 * The TablePress plugin versions installed are:
    1. TablePress Version 1.9.2 2.
   TablePress Extension Version 1.0 3. TablePress Extension: Table Auto Update Version
   1.2
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Funable-to-sort-date%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11267686)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * This all looks correct to me. Unfortunately, to check this out, I’d need to access
   the actual page with the table… Can you maybe make that page available?
 * Regards,
    Tobias
 *  Thread Starter [gtexeira](https://wordpress.org/support/users/gtexeira/)
 * (@gtexeira)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11268080)
 * I don’t have the ability to open the firewall rules.
 * Here is what I see from the dev tools report.
 * Uncaught SyntaxError: Invalid or unexpected token
 * $(‘#tablepress-7’).dataTable({“order”:[],”orderClasses”:false,”stripeClasses”:[“
   even”,”odd”],”paging”:false,”searching”:false,”info”:false,order:[[0,’desc’]],
   columnDefs:[{type:’date’,targets:[0]}]});
    -  This reply was modified 7 years, 2 months ago by [gtexeira](https://wordpress.org/support/users/gtexeira/).
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11268651)
 * Hi,
 * ah, ok, so you are getting an actual JS syntax error opposed to the sorting just
   not working.
 * Can you please check if you are using actual upright double and single quotation
   marks (`"` and `'`) in the “Custom Commands” text field? The forum software here
   uses typographically different ones (`”` and `’`) which would cause trouble.
 * Regards,
    Tobias
 *  Thread Starter [gtexeira](https://wordpress.org/support/users/gtexeira/)
 * (@gtexeira)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11272370)
 * hmm.
 * I updated the “custom commands” field with double quotes:
 * “order”: [ [ 0, “desc” ] ], “columnDefs”: [ { “type”: “date”, “targets”: [ 0 ]}]
 * still I have the report showing the oldest at the top.
    however the console now
   does not show an error.
 * The csv file looks like:
 * we,a,b,c,d,e,f,g,h,i,j,k,l
    2018-03-18,22,2,2,3,0,0,0,1,0,0,2,32 2018-03-19,159,9,9,2,0,0,0,2,0,0,16,197
   2018-03-20,132,4,3,6,0,1,1,0,1,1,12,161
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11272389)
 * Hi,
 * does the order change if you use `asc` instead of `desc` in the first part of
   the command?
 * For this date format (`yyyy-mm-dd`), you could actually also use the normal string
   sorting, i.e.
 *     ```
       "order": [ [ 0, "desc" ] ], "columnDefs": [ { "type": "string", "targets": [ 0 ] } ]
       ```
   
 * Does that work?
 * Regards,
    Tobias
 *  Thread Starter [gtexeira](https://wordpress.org/support/users/gtexeira/)
 * (@gtexeira)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11274587)
 * I copied and pasted your code above and it did not work with ASC and DESC. I 
   also did not get any errors with the page inspector. Is there a php source file
   that I need to update?
 * I also discovered that the sorting only works when I enable “Enable sorting of
   the table by the visitor.” If I disable it, it goes back to the original sort.
    -  This reply was modified 7 years, 2 months ago by [gtexeira](https://wordpress.org/support/users/gtexeira/).
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11275745)
 * Hi,
 * correct, all this only works if the “Sorting” checkbox is enabled on the “Edit”
   screen, as the “Custom Command” depends on this feature.
 * If you don’t want the table to be user-sortable, the “Custom Command” is not 
   the right way. You could then either one-time sort the table on the “Edit” screen(
   via the sort arrow icons in the column header cell), or use the TablePress Extension
   from [https://tablepress.org/extensions/table-row-order/](https://tablepress.org/extensions/table-row-order/)
   to achieve a pre-sorting when the table is shown to the visitor. As your date
   format can also be sorted as strings, both of these methods should work.
 * Regards,
    Tobias
 *  Thread Starter [gtexeira](https://wordpress.org/support/users/gtexeira/)
 * (@gtexeira)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11277152)
 * Hi Tobias,
 * Thank you for clarifying the expected sorting functionality when using the “Custom
   Command” field within the TablePress edit screen.
 * The TablePress Extension from [https://tablepress.org/extensions/table-row-order/](https://tablepress.org/extensions/table-row-order/)
   was the way to go, instead. This works as desired for me.
 * Thanks for your help.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11277174)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * Best wishes,
    Tobias
 * P.S.: In case you haven’t, please [rate TablePress](https://wordpress.org/support/plugin/tablepress/reviews/#new-post)
   here in the plugin directory. Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Unable to Sort Date’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [date sorting](https://wordpress.org/support/topic-tag/date-sorting/)

 * 9 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/unable-to-sort-date/#post-11277174)
 * Status: resolved