Since: DataTables 1.13

Register a date / time format for DataTables to use.


There are any number of formats for how dates and times might be displayed to the end user, so DataTables doesn't attempt to support any format other than ISO8601 by default from the data that it reads (i.e. for sorting). This method let's you register other formats through the use of the Moment.js or the Luxon libraries.

Pass a date / time format to this function and DataTables will automatically look for data that matches that format, and treat it as date / time data (for sorting, and advanced search with SearchBuilder). This allows DataTables to support any date / time format that your data might be given as.

It is worth noting that there are significant advantages to using ISO8601 as the "wire format" and then rendering the date / time data in a way that makes sense for each individual end user's locale - see this example for how that might done. The function here is used for detected pre-formatted dates and times.


function datetime( format [, locale ] )


Instruct DataTables to look for date and time data with the format given.



Detect dates such as '7 Jun 2011' using Moment.js:

DataTable.datetime('D MMM YYYY');
new DataTable('#example');

As above, but for Luxon:

DataTable.datetime('d MMM yyyy');
new DataTable('#example');