DateTime Standalone

DateTime is DataTables' own DateTime picker, which we mainly use within Editor and SearchBuilder extensions to provide a user friendly way to select values for dates and times. It is freely available under the MIT license if you wish to use it in some other capacity or as part of a custom extension for DataTables.

As well as standard JS Date formats, DateTime provides full integration with Moment, Luxon and Dayjs.

Download

The easiest way to get and use DateTime is to use the DataTables download builder where you can select the software that you wish to use on your page and have a single Javascript and CSS file created and hosted for you. You will need to make sure that you include this when using both the SearchBuilder package and Editor.

Alternatively, the individual files can be included on your page, a release package downloaded or the source control repository cloned on GitHub.

Initialisation

If you include the DateTime extension on your page, it is automatically available for every DataTable and extension on that page. The extensions that make use of DateTime initialise it themselves, so there is no need to worry about that. It is of course possible to initialise a DateTime instance outside of DataTables. To do this simply create a new instance of DateTime, passing in the target input element.

new DateTime(document.getElementById('myInput'));

It is also possible to initialise DateTime in a jQuery style.

$('#myInput').dtDateTime();

Configuration options are set by passing in a second argument (or a first if initialising using jQuery style), an object full of the options that are to be set. Full documentation is available for these.

new DateTime(document.getElementById('test'), {
    locale: 'fr'
});

There are also a variety of API methods that are available. They are documented here and an example of their use is included below.

var dt = new DateTime(document.getElementById('example'));
dt.val("2021-12-31");

To make use of Moment, Luxon or Dayjs the only initialisation that is required is to include them on the page. Doing this will then allow formats other than ISO8601 to be used. Examples using these libraries are available here for Moment, Luxon and Dayjs.

Features

DateTime adds the following features:

  • Easy Date and Time selection
  • Fully customisable date formats
  • Fully customisable locale
  • Fully internationalisable