Bootstrap 5/4/3 Date Time Picker With jQuery

File Size: 171 KB
Views Total: 57699
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Bootstrap 5/4/3 Date Time Picker With jQuery

Simplicite Bootstrap DateTimePicker adds calendar and time selection to Bootstrap 5, 4, and 3 form inputs. It builds on smalot's bootstrap-datetimepicker, with separate JavaScript and CSS builds for each Bootstrap version.

Features:

  • Localized date and time labels.
  • Custom date and time formats.
  • Minimum and maximum selectable dates.
  • Hour, day, month, year, and decade views.
  • Disabled weekdays, hours, and minutes.
  • Inline and popup picker modes.
  • Keyboard navigation.

How to use it:

1. Load the Bootstrap and Font Awesome 5 stylesheets, followed by jQuery 3.7.1 and Bootstrap JavaScript.

<!-- Bootstrap CSS and Font Awesome 5 -->
<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
<link rel="stylesheet" href="/path/to/cdn/all.min.css" />
<!-- jQuery and Bootstrap JavaScript -->
<script src="https://code.jquery.com/jquery-3.7.1.slim.min.js"></script>
<script src="/path/to/cdn/bootstrap.min.js"></script>

2. Load the picker CSS and JavaScript from bootstrap5/. The package also contains matching bootstrap4/ and bootstrap3/ builds.

<!-- Stylesheet -->
<link rel="stylesheet" href="/path/to/bootstrap5/css/bootstrap-datetimepicker.css" />
<!-- JavaScript -->
<script src="/path/to/bootstrap5/js/bootstrap-datetimepicker.js"></script>
<!-- Optional French locale -->
<script src="/path/to/bootstrap5/js/locales/bootstrap-datetimepicker.fr.js"></script>

3. Add a text input and initialize the picker.

<input type="text" value="2021-04-16 14:45" id="myPicker" class="default" />
$(function(){
  $(".default").datetimepicker();
});

4. For custom settings, replace the initialization in step 3 with this configuration. The plugin also reads the indicated data attributes.

$(".default").datetimepicker({

  container: 'body',

  // attribute: data-date-language
  language: 'en',

  // 'standard' or 'php'
  // attribute: data-format-type
  formatType: 'standard',

  // 'datetime' or 'time'
  formatViewType: 'datetime',

  // attribute: data-date-format
  format: 'yyyy-mm-dd hh:ii',

  // attribute: data-link-field
  linkField: false,

  // attribute: data-minute-step
  minuteStep: 5,

  // attribute: data-picker-position
  pickerPosition: 'bottom-right',

  // AM/PM display
  // attribute: data-show-meridian
  showMeridian: false,

  initialDate: new Date(),

  // attribute: data-z-index
  zIndex: undefined,

  // 0 = Sunday
  // 6 = Saturday
  // attribute: data-date-weekstart
  weekStart: 0,

  // attribute: data-date-startdate and data-date-enddate
  startDate: -Infinity,
  endDate: Infinity,

  // 0 = Sunday; 6 = Saturday
  // attribute: data-date-days-of-week-disabled
  daysOfWeekDisabled: [],

  // attribute: data-date-minute-disabled
  minutesDisabled: [],

  // attribute: data-date-hour-disabled
  hoursDisabled: [],

  autoOpen: true,

  // attribute: data-date-autoclose
  autoClose: false,

  // 0 or 'hour' for the hour view
  // 1 or 'day' for the day view
  // 2 or 'month' for month view (the default)
  // 3 or 'year' for the 12-month overview
  // 4 or 'decade' for the 10-year overview.
  // attribute: data-start-view
  startView: 2,

  // attribute: data-min-view
  minView: 0,

  // attribute: data-max-view
  maxView: 4,

  // attribute: data-view-mode-wheel-navigation
  wheelViewModeNavigation: false,

  // attribute: data-view-mode-wheel-navigation-inverse-dir
  wheelViewModeNavigationInverseDirection: false,

  // attribute: data-view-mode-wheel-navigation-delay
  wheelViewModeNavigationDelay: 100,

  // select the view from which the date will be selected
  // 'decade', 'year', 'month', 'day', 'hour'
  // attribute: data-view-select
  viewSelect: 0,

  // attribute: data-date-today-btn
  todayBtn: false,

  // attribute: data-date-today-highlight
  todayHighlight: false,

  // attribute: data-date-keyboard-navigation
  keyboardNavigation: true,

  // parse the input when the picker closes
  // attribute: data-date-force-parse
  forceParse: false,

});

API Methods.

// show the datetime picker
$('#myPicker').datetimepicker('show');

// hide the datetime picker
$('#myPicker').datetimepicker('hide');

// update the datetime picker
$('#myPicker').datetimepicker('update');

// read or set the selected date
var selectedDate = $('#myPicker').datetimepicker('getDate');
$('#myPicker').datetimepicker('setDate', new Date());

// set date limits
$('#myPicker').datetimepicker('setStartDate', '2020-01-01');
$('#myPicker').datetimepicker('setEndDate', '2030-01-01');

// disable days, hours, or minutes
$('#myPicker').datetimepicker('setDaysOfWeekDisabled', [0,6]);
$('#myPicker').datetimepicker('setHoursDisabled', [0, 1]);
$('#myPicker').datetimepicker('setMinutesDisabled', [15, 45]);

// destroy the datetime picker
$('#myPicker').datetimepicker('remove');

Events

$('#myPicker').datetimepicker()
  .on('changeDate', function(ev) {
    // Date selected
  })
  .on('changeMonth', function(ev) {
    // Month changed
  })
  .on('changeYear', function(ev) {
    // Year changed
  })
  .on('outOfRange', function(ev) {
    // Selection outside the configured date limits
  });

Changelog:

v1.2.1 (2025-10-14)

  • Labels the Today button "Now" when the selected format includes time.

v1.2.0 (2024-10-09)

  • WCAG milestone

v1.1.0 (2024-03-20)

  • Removed navigation arrows from the hour view in time-only mode.

v1.0.9 (2024-03-14)

  • Enhancement

v1.0.8 (2024-03-06)

  • Added more options

v1.0.7 (2021-10-12)

  • Added Bootstrap 5 version

v1.0.6 (2021-07-26)

  • Fixed minimum/maximum month handling.

2021-06-24

  • v1.0.4

2021-06-24

v1.0.2 (2021-05-12)

  • Updated JavaScript files.

Related Resources


This awesome jQuery plugin is developed by simplicitesoftware. For more Advanced Usages, please check the demo page or visit the official website.