jQuery Date Range Picker For Twitter Bootstrap

jQuery Date Range Picker For Twitter Bootstrap

A date range picker for Twitter Bootstrap for creating a dropdown menu to choose date ranges for reports, which would match the existing dropdown and button styles of Bootstrap.

See also:

How to use it:

1. Include jQuery script and daterangepicker.js

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="date.js"></script>
<script type="text/javascript" src="daterangepicker.js"></script>

2. Include Bootstrap CSS

<link rel="stylesheet" type="text/css" media="all" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" media="all" href="daterangepicker.css" />

3. Html Markup

<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="reservation">Reservation dates:
<div class="controls">
<div class="input-prepend">
<input type="text" name="reservation" id="reservation" />

4. Call the function and done.

<script type="text/javascript">
$(document).ready(function() {

5. Default settings for options.

// jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'
parentEl: 'body',
element: $(element),
// The start of the initially selected date range
startDate: '',
// The end of the initially selected date range
endDate: '',
// The earliest date a user may select
minDate: false,
// The latest date a user may select
maxDate: false,
// The maximum span between the selected start and end dates. 
// Can have any property you can add to a moment object (i.e. days, months)
dateLimit: false,
// Hide the apply and cancel buttons, and automatically apply a new date range as soon as two dates or a predefined range is selected
autoApply: false,
// Show only a single calendar to choose one date, instead of a range picker with two calendars, the start and end dates provided to your callback will be the same single date chosen
singleDatePicker: false,
// Show year and month select boxes above calendars to jump to a specific month and year
showDropdowns: false,
// Show localized week numbers at the start of each week on the calendars
showWeekNumbers: false,
// Show ISO week numbers at the start of each week on the calendars
showISOWeekNumbers: false,
// Allow selection of dates with times, not just dates
timePicker: false,
// Use 24-hour instead of 12-hour times, removing the AM/PM selection
timePicker24Hour: false,
// Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30)
timePickerIncrement: 1,
// Show seconds in the timePicker
timePickerSeconds: false,
// When enabled, the two calendars displayed will always be for two sequential months (i.e. January and February), and both will be advanced when clicking the left or right arrows above the calendars. 
// When disabled, the two calendars can be individually advanced and display any month/year.
linkedCalendars: true,
// Indicates whether the date range picker should automatically update the value of an <input> element it's attached to at initialization and when the selected dates change.
autoUpdateInput: true,
// Normally, if you use the ranges option to specify pre-defined date ranges, calendars for choosing a custom date range are not shown until the user clicks "Custom Range". When this option is set to true, the calendars for choosing a custom date range are always shown instead.
alwaysShowCalendars: false,
// Set predefined date ranges the user can select from. 
// Each key is the label for the range, and its value an array with two dates representing the bounds of the range
ranges: {},
// 'left'/'right'/'center'
// Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to
opens: 'right',
// string: 'down' or 'up' 
// Whether the picker appears below (default) or above the HTML element it's attached to
drops: 'down',
// CSS class names that will be added to all buttons in the picker
buttonClasses: 'btn btn-sm',
// CSS class string that will be added to the apply button
applyClass: 'btn-success',
// CSS class string that will be added to the cancel button
cancelClass: 'btn-default',
// Allows you to provide localized strings for buttons and labels, customize the date display format, and change the first day of week for the calendars
locale: {
  format: 'MM/DD/YYYY',
  separator: ' - ',
  applyLabel: 'Apply',
  cancelLabel: 'Cancel',
  weekLabel: 'W',
  customRangeLabel: 'Custom Range',
  daysOfWeek: moment.weekdaysMin(),
  monthNames: moment.monthsShort(),
  firstDay: moment.localeData().firstDayOfWeek()

6. API.

  • show.daterangepicker: Triggered when the picker is shown
  • hide.daterangepicker: Triggered when the picker is hidden
  • showCalendar.daterangepicker: Triggered when the calendar(s) are shown
  • hideCalendar.daterangepicker: Triggered when the calendar(s) are hidden
  • apply.daterangepicker: Triggered when the apply button is clicked, or when a predefined range is clicked
  • cancel.daterangepicker: Triggered when the cancel button is clicked

Change Log:


  • v2.1.27


  • Change 'background' to 'background-color' to preserve Bootstrap 'background-clip'.


  • v2.1.24: bugfix


  • v2.1.23: bugfix


  • v2.1.22: Experimental: Clicking on the right-hand text input in the UI allows re-selection of the end of the current date range without first re-selecting the beginning on the calendar


  • v2.1.21


  • v2.1.18


  • v2.1.14

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

  • Publication date: 12.12.2017
  • Source