Date Picker MDB Pro component

Bootstrap Date Picker

Bootstrap date picker is a plugin that adds the function of selecting time without the necessity of using custom JavaScript code.


Basic example MDB Pro component

Initialization required

To use our Material DatePicker you have to initialize it first with the code below.


        <div class="md-form">
          <input placeholder="Selected date" type="text" id="date-picker-example" class="form-control datepicker">
          <label for="date-picker-example">Try me...</label>
        </div>
      


        // Data Picker Initialization
        $('.datepicker').pickadate();
      

Note: Javascript numeration

Months in a JavaScript Date object are zero-indexed. Meaning, new Date(2015, 3, 20) is 20 April, 2016.

To stay consistent with this, whenever an integer is used in reference to a month, pickadate treats it as zero-indexed. Dates as strings are still parsed as expected.


Default settings

These are the default settings applied to the basic invocation above. To change them, simply initialize the Date Picker with the desired values.



        // Strings and translations
        monthsFull: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October',
        'November', 'December'],
        monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        weekdaysFull: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
        weekdaysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        showMonthsShort: undefined,
        showWeekdaysFull: undefined,

        // Buttons
        today: 'Today',
        clear: 'Clear',
        close: 'Close',

        // Accessibility labels
        labelMonthNext: 'Next month',
        labelMonthPrev: 'Previous month',
        labelMonthSelect: 'Select a month',
        labelYearSelect: 'Select a year',

        // Formats
        format: 'd mmmm, yyyy',
        formatSubmit: undefined,
        hiddenPrefix: undefined,
        hiddenSuffix: '_submit',
        hiddenName: undefined,

        // Editable input
        editable: undefined,

        // Dropdown selectors
        selectYears: undefined,
        selectMonths: undefined,

        // First day of the week
        firstDay: undefined,

        // Date limits
        min: undefined,
        max: undefined,

        // Disable dates
        disable: undefined,

        // Root picker container
        container: undefined,

        // Hidden input container
        containerHidden: undefined,

        // Close on a user action
        closeOnSelect: true,
        closeOnClear: true,

        // Events
        onStart: undefined,
        onRender: undefined,
        onOpen: undefined,
        onClose: undefined,
        onSet: undefined,
        onStop: undefined,

        // Classes
        class: {

        // The element states
        input: 'picker__input',
        active: 'picker__input--active',

        // The root picker and states *
        picker: 'picker',
        opened: 'picker--opened',
        focused: 'picker--focused',

        // The picker holder
        holder: 'picker__holder',

        // The picker frame, wrapper, and box
        frame: 'picker__frame',
        wrap: 'picker__wrap',
        box: 'picker__box',

        // The picker header
        header: 'picker__header',

        // Month navigation
        navPrev: 'picker__nav--prev',
        navNext: 'picker__nav--next',
        navDisabled: 'picker__nav--disabled',

        // Month & year labels
        month: 'picker__month',
        year: 'picker__year',

        // Month & year dropdowns
        selectMonth: 'picker__select--month',
        selectYear: 'picker__select--year',

        // Table of dates
        table: 'picker__table',

        // Weekday labels
        weekdays: 'picker__weekday',

        // Day states
        day: 'picker__day',
        disabled: 'picker__day--disabled',
        selected: 'picker__day--selected',
        highlighted: 'picker__day--highlighted',
        now: 'picker__day--today',
        infocus: 'picker__day--infocus',
        outfocus: 'picker__day--outfocus',

        // The picker footer
        footer: 'picker__footer',

        // Today, clear, & close buttons
        buttonClear: 'picker__button--clear',
        buttonClose: 'picker__button--close',
        buttonToday: 'picker__button--today'
        }

      

Customization


Strings

Change the month and weekday labels as you wish:


        $('.datepicker').pickadate({
          weekdaysShort: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
          showMonthsShort: true
        })
      

Buttons

Change the text, or hide a button completely, by passing a false-y value:


        $('.datepicker').pickadate({
          today: '',
          clear: 'Clear selection',
          close: 'Cancel'
        })
      

Accessibility labels

Change the title attributes to several elements within the picker:


        $('.datepicker').pickadate({
          labelMonthNext: 'Go to the next month',
          labelMonthPrev: 'Go to the previous month',
          labelMonthSelect: 'Pick a month from the dropdown',
          labelYearSelect: 'Pick a year from the dropdown',
          selectMonths: true,
          selectYears: true
        })
      

Translations

The picker can be extended to add support for internationalization. Translations for over 40 languages are available out of the box, which you can include in one of two ways:


        // Extend the default picker options for all instances.
          $.extend($.fn.pickadate.defaults, {
          monthsFull: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre',
          'Novembre', 'Décembre'],
          weekdaysShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
          today: 'aujourd\'hui',
          clear: 'effacer',
          formatSubmit: 'yyyy/mm/dd'
        })

        // Or, pass the months and weekdays as an array for each invocation.
        $('.datepicker').pickadate({
          monthsFull: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre',
          'Novembre', 'Décembre'],
          weekdaysShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
          today: 'aujourd\'hui',
          clear: 'effacer',
          formatSubmit: 'yyyy/mm/dd'
        })
      

Note:

When using translations, specify formatSubmit and data-value to ensure the date parses correctly regardless of locale.

Formats

Display a human-friendly format and use an alternate one to submit to the server.

This is done by creating a new hidden input element with the same name attribute as the original with an optional prefix/suffix:


        $('.datepicker').pickadate({
        // Escape any “rule” characters with an exclamation mark (!).
        format: 'You selecte!d: dddd, dd mmm, yyyy',
        formatSubmit: 'yyyy/mm/dd',
        hiddenPrefix: 'prefix__',
        hiddenSuffix: '__suffix'
        })
      

Send the hidden value only

A majority of the time, the value that needs to be sent to the server is just the hidden value — and not the visible one. To make this happen, use the hiddenName option.

This essentially nullifies hiddenPrefix and hiddenSuffix, strips the name attribute from the source input, and then sets it as the name of the hidden input:


        $('.datepicker').pickadate({
        weekdaysShort: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
        showMonthsShort: true
        })
      

Pre-fill values using custom formats or translations

When using a custom formatting rule for the format option, or when using translations, the input element should be given a data-value attribute formatted using the formatSubmit — the element’s value can be left blank. This helps to parse the date from custom formats into various languages:


        <input data-value="2015/04/20">
      

Formatting rules

The following rules can be used to format any date:

Rule Description Result
d Date of the month 1 – 31
dd Date of the month with a leading zero 01 – 31
ddd Day of the week in short form Sun – Sat
dddd Day of the week in full form Sunday – Saturday
m Month of the year 1 – 12
mm Month of the year with a leading zero 01 – 12
mmm Month name in short form Jan – Dec
mmmm Month name in full form January – December
yy Year in short form * 00 – 99
yyyy Year in full form 2000 – 2999

Note:

If you use the yy rule in the format option, you must specify the yyyy rule in the formatSubmit option with the appropriate data-value attribute to ensure the the date parses accurately.

Never use the yy rule in the formatSubmit option.

Heading

By default, typing into the input is disabled by giving it a readOnly attribute. Doing so ensures that virtual keyboards don’t pop open on touch devices. It is also a confirmation that values passed to the server will be of a consistent format.

However, this behavior can be changed using the editable option:


        $('.datepicker').pickadate({
        editable: true
        })
      

Note:

An important thing to note here is that the above disables keyboard bindings on the input element, such as arrow keys opening the picker. You will have to add your own bindings as you see fit.

Using html5 attributes

Because each input is readOnly by default, HTML5 attributes, such as required and pattern, do not get enforced.

To enable default browser behavior on these attributes, set the editable property to true.

Display select menus to pick the month and year. Anything truth-y enables the selectors and anything false-y switches them into text:


        $('.datepicker').pickadate({
        selectYears: true,
        selectMonths: true
        })
      

You can also specify the number of years to show in the dropdown using an even integer — half before and a half after the year in focus:


        $('.datepicker').pickadate({
        // `true` defaults to 10.
        selectYears: 4
        })
      

First weekday

The first day of the week can be set to either Sunday or Monday. Anything truth-y sets it as Monday and anything false-y as Sunday:


        $('.datepicker').pickadate({
        firstDay: 1
        })
      

Date limits

Set the minimum and maximum selectable dates on the picker:

1. Using JavaScript Date object:


        $('.datepicker').pickadate({ min: new Date(2015,3,20),
        max: new Date(2015,7,14)
        })
      

2. Using arrays formatted as [YEAR,MONTH,DATE]


        $('.datepicker').pickadate({ min: [2015,3,20],
        max: [2015,7,14]
        })
      

3. Using integers or a boolean


        $('.datepicker').pickadate({
        // An integer (positive/negative) sets it relative to today.
        min: -15,
        // `true` sets it to today. `false` removes any limits.
        max: true
        })
      

Disable dates

Disable a specific or arbitrary set of dates selectable on the picker. You can do it by:

1. Using JavaScript Date object


        $('.datepicker').pickadate({
        disable: [
        new Date(2015,3,13),
        new Date(2015,3,29)
        ]
        })
      

2. Using arrays formatted as [YEAR,MONTH,DATE]


        $('.datepicker').pickadate({
        disable: [
        [2015,3,3],
        [2015,3,12],
        [2015,3,20]
        ]
        })
      

3. Using integers as days of the week (1 to 7)


        $('.datepicker').pickadate({
        disable: [
        1, 4, 7
        ]
        })
      

4. Using objects as a range of dates


        $('.datepicker').pickadate({
        disable: [
        { from: [2016,2,14], to: [2016,2,27] }
        ]
        })
      

Note:

When it comes to disabling particular dates, the values for from & to can be a JavaScript Date object, an array formatted as [YEAR,MONTH,DATE] or a booleanvalue (true sets the date as “today”).

The values can also be integers representing dates relative to the other, where to can only be positive ({ from: [2016,3,12], to: 10 }), while from can only be negative ({ from: -10, to: true })

5. Disabling all with a set of exceptions

Enable only a specific or arbitrary set of dates by setting the the first item in the collection as true:


        $('.datepicker').pickadate({
        disable: [
        true,
        1, 4, 7,
        [2015,3,3],
        [2015,3,12],
        [2015,3,20],
        new Date(2015,3,13),
        new Date(2015,3,29)
        ]
        })
      

6. Disabling ranges with exceptions

Enable dates that fall within a range of disabled dates by adding an the inverted parameter to the item within the collection:


        $('.datepicker').pickadate({
        disable: [
        5,
        [2015, 10, 21, 'inverted'],
        { from: [2016, 3, 15], to: [2016, 3, 25] },
        [2016, 3, 20, 'inverted'],
        { from: [2016, 3, 17], to: [2016, 3, 18], inverted: true }
        ]
        })
      

Close on a user action

When a date is selected or the “clear” button is pressed, the picker closes. To change this behavior, use the following options:


        $('.datepicker').pickadate({
        closeOnSelect: false,
        closeOnClear: false
        })
      

Events

Fire off events as the user interacts with the picker:


        $('.datepicker').pickadate({
        onStart: function() {
        console.log('Hello there :)')
        },
        onRender: function() {
        console.log('Whoa.. rendered anew')
        },
        onOpen: function() {
        console.log('Opened up')
        },
        onClose: function() {
        console.log('Closed now')
        },
        onStop: function() {
        console.log('See ya.')
        },
        onSet: function(context) {
        console.log('Just set stuff:', context)
        }
        })
      

"From - to" Date Pickers (date range)

Date Pickers are great for selecting a particular date, but sometimes we need more than that - take periods, for example. Setting a starting and finishing date requires cooperation between the two Pickers, as the end date being set to a time before the start date makes no sense. Luckily, we can tie two Date Pickers together (their inputs, min and max properties, to be exact). We achieve it using getters and setters and here's how:



        <!--Grid row-->
        <div class="row">

          <!--Grid column-->
          <div class="col-md-6 mb-4">

            <div class="md-form">
              <!--The "from" Date Picker -->
              <input placeholder="Selected starting date" type="text" id="startingDate" class="form-control datepicker">
              <label for="startingDate">start</label>
            </div>

          </div>
          <!--Grid column-->

          <!--Grid column-->
          <div class="col-md-6 mb-4">

            <div class="md-form">
              <!--The "to" Date Picker -->
              <input placeholder="Selected ending date" type="text" id="endingDate" class="form-control datepicker">
              <label for="endingDate">end</label>
            </div>

          </div>
          <!--Grid column-->

        </div>
        <!--Grid row-->

      


        // Get the elements
        var from_input = $('#startingDate').pickadate(),
        from_picker = from_input.pickadate('picker')
        var to_input = $('#endingDate').pickadate(),
        to_picker = to_input.pickadate('picker')

        // Check if there’s a “from” or “to” date to start with and if so, set their appropriate properties.
        if ( from_picker.get('value') ) {
        to_picker.set('min', from_picker.get('select'))
        }
        if ( to_picker.get('value') ) {
        from_picker.set('max', to_picker.get('select'))
        }

        // Apply event listeners in case of setting new “from” / “to” limits to have them update on the other end. If
        ‘clear’ button is pressed, reset the value.
        from_picker.on('set', function(event) {
        if ( event.select ) {
        to_picker.set('min', from_picker.get('select'))
        }
        else if ( 'clear' in event ) {
        to_picker.set('min', false)
        }
        })
        to_picker.on('set', function(event) {
        if ( event.select ) {
        from_picker.set('max', to_picker.get('select'))
        }
        else if ( 'clear' in event ) {
        from_picker.set('max', false)
        }
        })
      

Getting started : download & setup


Download

All the components and features are part of MDBootstrap package.

MDBootstrap (Material Design for Bootstrap) is a free (MIT Licensed) framework combining Material Design and the newest Bootstrap 4.

Click the button below to go to Download Page, where you can download MDBootstrap package.

MDBootstrap Download MDBootstrap About

MDB Pro

Using components and features labeled as MDB Pro component requires MDB Pro package.

Click the button below to learn more about MDBbootstrap Pro package

MDBootstrap Pro

Tutorials

If you need additional help to start, use our "5 min Quick Start" or "Full tutorial" resources.

5 min Quick Start Full Tutorial

Compilation

To reduce a weight of MDBootstrap package, you can compile your own, custom package containing only components and features you need.

Map of dependencies of SCSS files in MDBootstrap:


    Legend:

    '-->' means 'required'

    All free and pro files require files from 'core' catalog

    'none' means 'this component doesn't require anything except core files'

    A file wrapped by `< >` means that this file make the base component prettier but it isn't necessary for the proper working

    All PRO components require 'pro/_variables.scss' file

    scss/
    |
    |-- core/
    |   |
    |   |-- bootstrap/
    |   |	|-- _functions.scss
    |   |	|-- _variables.scss
    |   |
    |   |-- _colors.scss
    |   |-- _global.scss
    |   |-- _helpers.scss
    |   |-- _masks.scss
    |   |-- _mixins.scss
    |   |-- _typography.scss
    |   |-- _variables.scss
    |   |-- _waves.scss
    |
    |-- free/
    |   |-- _animations-basic.scss --> none
    |   |-- _animations-extended.scss --> _animations-basic.scss
    |   |-- _buttons.scss --> none
    |   |-- _cards.scss --> none <_buttons.scss>
    |   |-- _dropdowns.scss --> none <_buttons.scss>
    |   |-- _input-group.scss --> _forms.scss, _buttons.scss, _dropdowns.scss
    |   |-- _navbars.scss --> none <_buttons.scss, _forms.scss, _input-group.scss>
    |   |-- _pagination.scss --> none
    |   |-- _badges.scss --> none
    |   |-- _modals.scss --> _buttons.scss, _forms.scss (PRO --> _tabs.scss)
    |   |-- _carousels.scss --> <_buttons.scss>
    |   |-- _forms.scss --> none
    |   |-- _msc.scss --> none <_buttons.scss, _forms.scss, _cards.scss>
    |   |-- _footers.scss none <_buttons.scss> (PRO: )
    |   |-- _list-group.scss --> none
    |   |-- _tables.scss --> none (PRO: _material-select.scss, pro/_forms.scss, _checkbox.scss, pro/_buttons.scss, pro/_cards.scss, _pagination.scss, pro/_msc.scss)
    |   |-- _depreciated.scss
    |
    |-- pro/
    |   |
    |   |-- picker/
    |   |   |-- _default.scss --> none
    |   |   |-- _default-time.scss --> _default.scss, free/_forms.scss, free/_buttons.scss, pro/_buttons.scss, free/_cards.scss
    |   |   |-- _default-date.scss --> _default.scss, free/_forms.scss
    |   |
    |   |-- sections/
    |   |   |-- _templates.scss --> _sidenav.scss
    |   |   |-- _social.scss --> free/_cards.scss, free/ _forms.scss, free/_buttons.scss, pro/_buttons.scss,
    |   |   |-- _team.scss --> free/_buttons.scss, pro/_buttons.scss, free/_cards.scss, pro/_cards.scss
    |   |   |-- _testimonials.scss --> free/_carousels.scss, pro/_carousels.scss, free/_buttons.scss, pro/_buttons.scss
    |   |   |-- _magazine.scss --> _badges.scss
    |   |   |-- _pricing.scss --> free/_buttons.scss, pro/_buttons.scss
    |   |   |-- _contacts.scss --> free/_forms.scss, pro/_forms.scss, free/_buttons.scss, pro/_buttons.scss
    |   |
    |   |-- _variables.scss
    |   |-- _buttons.scss --> free/_buttons.scss, pro/_msc.scss, _checkbox.scss, _radio.scss
    |   |-- _social-buttons.scss --> free/_buttons.scss, pro/_buttons.scss
    |   |-- _tabs.scss --> _cards.scss
    |   |-- _cards.scss --> free/_cards.scss <_buttons.scss, _social-buttons.scss>
    |   |-- _dropdowns.scss --> free/_dropdowns.scss, free/_buttons.scss
    |   |-- _navbars.scss --> free/_navbars.scss  (PRO: )
    |   |-- _scrollspy.scss --> none
    |   |-- _lightbox.scss --> none
    |   |-- _chips.scss --> none
    |   |-- _msc.scss --> none
    |   |-- _forms.scss --> none
    |   |-- _radio.scss --> none
    |   |-- _checkbox.scss --> none
    |   |-- _material-select.scss --> none
    |   |-- _switch.scss --> none
    |   |-- _file-input.scss --> free/_forms.scss, free/_buttons.scss
    |   |-- _range.scss --> none
    |   |-- _input-group.scss --> free/_input-group.scss and the same what free input group, _checkbox.scss, _radio.scss
    |   |-- _autocomplete.scss --> free/_forms.scss
    |   |-- _accordion.scss --> pro/_animations.scss, free/_cards.scss
    |   |-- _parallax.scss --> none
    |   |-- _sidenav.scss --> free/_forms.scss, pro/_animations.scss, sections/_templates.scss
    |   |-- _ecommerce.scss --> free/_cards.scss, pro/_cards.scss, free/_buttons.scss, pro/_buttons.scss, pro/_msc.scss
    |   |-- _carousels.scss --> free/_carousels.scss, free/_cards.scss, free/_buttons.scss 
    |   |-- _steppers.scss --> free/_buttons.scss
    |   |-- _blog.scss --> none
    |   |-- _toasts.scss --> free/_buttons.scss
    |   |-- _animations.scss --> none
    |   |-- _charts.scss --> none
    |   |-- _progress.scss --> none
    |   |-- _scrollbar.scss --> none
    |   |-- _skins.scss --> none
    |   |-- _depreciated.scss
    |
    `-- _custom-skin.scss
    `-- _custom-styles.scss
    `-- _custom-variables.scss
    `-- mdb.scss

  

Map of dependencies of JavaScript modules in MDBootstrap:


    Legend:

    '-->' means 'required'

    All files require jQuery and bootstrap.js

    js/
    ├── dist/
    │   ├── buttons.js
    │   ├── cards.js
    │   ├── character-counter.js
    │   ├── chips.js
    │   ├── collapsible.js --> vendor/velocity.js
    │   ├── dropdown.js --> Popper.js, jquery.easing.js
    │   ├── file-input.js
    │   ├── forms-free.js
    │   ├── material-select.js --> dropdown.js
    │   ├── mdb-autocomplete.js
    │   ├── preloading.js
    │   ├── range-input.js --> vendor/velocity.js
    │   ├── scrolling-navbar.js
    │   ├── sidenav.js --> vendor/velocity.js, vendor/hammer.js, vendor/jquery.hammer.js
    │   └── smooth-scroll.js
    ├── _intro-mdb-pro.js
    ├── modules.js
    ├── src/
    │   ├── buttons.js
    │   ├── cards.js
    │   ├── character-counter.js
    │   ├── chips.js
    │   ├── collapsible.js --> vendor/velocity.js
    │   ├── dropdown.js --> Popper.js, jquery.easing.js
    │   ├── file-input.js
    │   ├── forms-free.js
    │   ├── material-select.js --> dropdown.js
    │   ├── mdb-autocomplete.js
    │   ├── preloading.js
    │   ├── range-input.js --> vendor/velocity.js
    │   ├── scrolling-navbar.js
    │   ├── sidenav.js --> vendor/velocity.js, vendor/hammer.js, vendor/jquery.hammer.js
    │   └── smooth-scroll.js
    └── vendor/
        ├── addons/
        │   ├── datatables.js
        │   └── datatables.min.js
        ├── chart.js
        ├── enhanced-modals.js
        ├── hammer.js
        ├── jarallax.js
        ├── jarallax-video.js --> vendor/jarallax.js
        ├── jquery.easing.js
        ├── jquery.easypiechart.js
        ├── jquery.hammer.js --> vendor/hammer.js
        ├── jquery.sticky.js
        ├── lightbox.js
        ├── picker-date.js --> vendor/picker.js
        ├── picker.js
        ├── picker-time.js --> vendor/picker.js
        ├── scrollbar.js
        ├── scrolling-navbar.js
        ├── toastr.js
        ├── velocity.js
        ├── waves.js
        └── wow.js
  

Compilation & Customization tutorial

If you need additional help to compile your custom package, use our Compilation & Customization tutorial

Compilation & Customization tutorial

Integrations with Angular, React or Vue

Apart from standard Bootstrap integration with jQuery, MDBootstrap provides integrations with Angular, React and Vue.

About MDB Angular About MDB React About MDB Vue