Title: Sorting Dates in Data Tables
Last modified: October 19, 2021

---

# Sorting Dates in Data Tables

 *  Resolved [Judson Mitchell](https://wordpress.org/support/users/judsonmitchell/)
 * (@judsonmitchell)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/)
 * Peter,
 * I have a db column in the DATE format (YYYY-MM-DD). When I load up the table 
   on my page, dataTables will transform the date to a textual date but it will 
   not sort properly (i.e, sorts it as a string). I read some support threads on
   the [dataTables forum](https://datatables.net/forums/discussion/45692/how-to-date-sort-as-date-instead-of-string),
   but that seems to involve loading moment.js and writing some custom js, which
   I would like to avoid if possible.
 * Do you have any other suggestions for sorting this table by date? Thanks very
   much.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsorting-dates-in-data-tables%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Passionate Programmer Peter](https://wordpress.org/support/users/peterschulznl/)
 * (@peterschulznl)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-14987678)
 * Hi Judson,
 * I think the problem is that your date column is sorted naturally:
    [https://stackoverflow.com/questions/50836008/jquery-datatable-sort-not-working-for-date-column](https://stackoverflow.com/questions/50836008/jquery-datatable-sort-not-working-for-date-column)
 * I think this happens when you change the date format. What format are you using?
   And where did you define it? In general WP settings? Or the plugin settings? 
   Or both?
 * Let me try to test a publication with the same settings and then see what needs
   to be done to fix this. A redefinition of the columnDefs variable might fix this
   issue.
 * Please let me know,
    Peter
 *  Plugin Author [Passionate Programmer Peter](https://wordpress.org/support/users/peterschulznl/)
 * (@peterschulznl)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-14990309)
 * Hi Judson,
 * I was trying to reproduce this issue. It looks like it works fine as long as 
   a column is of type date. When I convert the data type to string I’m getting 
   the same results. Can you please check the data type of your date column? Is 
   the original column converted?
 * Thanks,
    Peter
 *  Thread Starter [Judson Mitchell](https://wordpress.org/support/users/judsonmitchell/)
 * (@judsonmitchell)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-14990429)
 * Peter,
 * Thanks for looking into this. In my MySQL database, the data type for this column
   is DATE. Data is entered in YYYY-MM-DD format. When I look at Data Explorer for
   this table, “Columns” has the column data type as “Date”. When I load the table
   in phpmyadmin, it sorts fine. On my Data Publisher produced page, I notice that
   JS is transforming the MySQL date format into an English string, e.g, 2019-02-
   01 becomes “February 1st, 2019”. That’s fine, but when I go to sort the date 
   columns, the sort is done by the first letter of the month.
 * Is there somewhere else other than in the table definition that I have to set
   the data type for the column?
 *  Thread Starter [Judson Mitchell](https://wordpress.org/support/users/judsonmitchell/)
 * (@judsonmitchell)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-14993413)
 * Peter,
 * Thanks very much for the offer. You are always so helpful! I went into the WP
   settings and see that is in fact WordPress that is modifying the date format.
   I changed the date format to MySQL format and the table works fine now. Presumably,
   I could use moment.js or date-fns to change the display format of the date after
   sorting, but I think I’ll take a pass on that for now.
 * JM
 *  Plugin Author [Passionate Programmer Peter](https://wordpress.org/support/users/peterschulznl/)
 * (@peterschulznl)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-14993555)
 * Good to hear you fixed it Judson! 😊
 * Thanks for reporting back,
    Peter
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [4 years, 6 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-15117908)
 * [@peterschulznl](https://wordpress.org/support/users/peterschulznl/) I’ve deleted
   your offer to login to your user’s site. I’m am 100% sure you mean well but please
   _never ask for credentials on these forums._
 * [https://wordpress.org/support/guidelines/#the-bad-stuff](https://wordpress.org/support/guidelines/#the-bad-stuff)
 * Now for the why: The internet is a wonderful place full of very nice people and
   a few very bad ones. I’m sure everyone here is very nice however, by giving some
   ones keys to your house you are trusting they wont steal anything. Likewise the
   person who takes the keys is now responsible for the house FOREVER.
 * If something was to go wrong, then you the author may well legally become liable
   for damages, which they would not normally have been as their software is provided
   without warranty.
 * **Please be aware that repeatedly asking for credentials will result in us escalating
   this to the plugins team.**
 * It’s never necessary to do that. Here’s why.
 * There are many ways to get information you need and accessing the user’s site
   is not one of them. That’s going too far.
    - Ask for a link to the [http://pastebin.com/](http://pastebin.com/) log of 
      the user’s web server error log.
    - Ask the user to create and post a link to their `phpinfo();` output.
    - Ask the user to install the [Health Check plugin](https://wordpress.org/support/plugin/health-check/)
      and get the data that way.
    - Walk the user through [enabling WP_DEBUG and how to log that output to a file and how to share that file.](https://codex.wordpress.org/WP_DEBUG#WP_DEBUG_LOG_and_WP_DEBUG_DISPLAY)
    - Walk the user through basic troubleshooting steps such and disabling all other
      plugins, clear their cache and cookies and try again.
    - Ask the user for the step-by-step on how they can reproduce the problem.
 * You get the idea.
 * Volunteer support is not easy. But these forums need to a safe place for all 
   users, experienced or new. Accessing their system that way is a short cut that
   will get you into real trouble in these forums.

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

The topic ‘Sorting Dates in Data Tables’ is closed to new replies.

 * ![](https://ps.w.org/wp-data-access/assets/icon-256x256.png?rev=3299063)
 * [WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards](https://wordpress.org/plugins/wp-data-access/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-data-access/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-data-access/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-data-access/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-data-access/reviews/)

## Tags

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

 * 6 replies
 * 3 participants
 * Last reply from: [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * Last activity: [4 years, 6 months ago](https://wordpress.org/support/topic/sorting-dates-in-data-tables/#post-15117908)
 * Status: resolved