Vanilla JS
jQuery
Vanilla JS

What is this?

Auto
Light
Dark

What is this?

DataTables example Ordering formatted dates (Moment.js)

You might wish to tell DataTables about a specific date/time format that your data contains, but either you don't wish to transform it into a different format, or you aren't sure which columns the date/time data will be in (i.e. can't use the datetime rendering function). For such cases, we provide a DataTable.datetime() function to which you provide a format string. This will instruct DataTables to look for and parse data in such a format.

As with DataTable's other date and time methods, DataTable.datetime() supports both Moment.js and Luxon. In this example we are using Moment.js. For a full range of its formatting options, please see the Moment.js documentation. Note that the parsing is strict - your assigned format must exactly match the data.

NamePositionOfficeAgeStart dateSalary
Airi Satou Accountant Tokyo 33 28 Nov 2008 $162,700
Angelica Ramos Chief Executive Officer (CEO) London 47 9 Oct 2009 $1,200,000
Ashton Cox Junior Technical Author San Francisco 66 12 Jan 2009 $86,000
Bradley Greer Software Engineer London 41 13 Oct 2012 $132,000
Brenden Wagner Software Engineer San Francisco 28 7 Jun 2011 $206,850
Brielle Williamson Integration Specialist New York 61 2 Dec 2012 $372,000
Bruno Nash Software Engineer London 38 3 May 2011 $163,500
Caesar Vance Pre-Sales Support New York 21 12 Dec 2011 $106,450
Cara Stevens Sales Assistant New York 46 6 Dec 2011 $145,600
Cedric Kelly Senior Javascript Developer Edinburgh 22 29 Mar 2012 $433,060
NamePositionOfficeAgeStart dateSalary
Showing 1 to 10 of 57 entries

The Javascript shown below is used to initialise the table shown in this example:

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

In addition to the above code, the following Javascript library files are loaded for use in this example: