DataTable.datetime()
Register a date / time format for DataTables to use.
Description
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.
Type
function datetime( format [, locale ] )
- Description:
Instruct DataTables to look for date and time data with the format given.
- Parameters:
Name Type Optional 1 format
No The date / time format to detect data in. Please refer to the Moment.js or Luxon document for the full list of tokens, depending on which of the two libraries you are using.
2 locale
Yes The locale to pass to Moment.js / Luxon.
Examples
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');