Bootstrap Datepicker

What is a Bootstrap Datepicker?

It is used to display a calendar with the date, month, and time from a dropdown menu.

We will use an example to see how the date pickers are used in bootstrap. The time can be displayed in various formats, and the most frequently used formats are “MM:DD:YYYY”, “DD:MM:YYYY”, “YYYY:MM:DD”, etc.

The default format is, "MM:DD:YYYY”.

Here,

MM:

  • Refers to the months.
  • Can take the values from 01 to 12, i.e. January, February, March, April, May, June, July, August, September, October, November and December.

DD:

  • Refers to the date.
  • Lies between 01 to 31.

YYYY:

  • Refers to the years.
  • For example, 2020, 2002, 2001, 2045 etc.

Usage of date-pickers

  • Selecting interview slots
  • Marking meeting schedules
  • In Time tables
  • Exam Slot bookings
  • Choosing movie/show timings etc.

Example 1:

<!DOCTYPE html>  
<html lang = "en">  
<head>      
  <meta charset = "UTF-8">  
  <meta name = "viewport" content = "width=device-width, initial-scale=1.0">  
  <link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">  
  <title>Bootstrap DatePicker Example</title>  
  <style>
     body{
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        color: white;
        background-color: black;
     }
     .container{
        margin: auto;
        padding: auto;
     }
     #content{
        align-items: center;
        align-self: center;
        align-content: center;
        text-align: center;
     }
  </style>
</head>  
  
<body>  
   <div class="container">
      <div class="row">
    
          <div class = "col-sm-12 col-lg-12 " id = "content" >   
            <h2>Bootstrap Datepicker Example</h2>  
            <br>
              <p>Following is an example to demonstrate the Bootstrap Datepicker Example:</p><br>
           <input type = "date" name = "date">  
          </div>  
       
   </div>
   </div>
  <script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>  
  <script src ="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
</body>  
</html>  

Output:

Bootstrap Datepicker

We can see the calendar from the dropdown and choose a date accordingly, as shown below,

Bootstrap Datepicker

Example 2:

<!DOCTYPE html>  
<html lang = "en">  
<head> 
   <title>Bootstrap Datepicker Example</title>     
  <meta charset = "UTF-8">  
  <meta name = "viewport" content = "width=device-width, initial-scale=1.0">  
<link rel="stylesheet" href="https://formden.com/static/cdn/bootstrap-iso.css" /> 


<link rel="stylesheet" href="https://formden.com/static/cdn/font-awesome/4.4.0/css/font-awesome.min.css" />


<style>
.bootstrap-iso .formden_header h2, .bootstrap-iso .formden_header p, .bootstrap-iso form{
   font-family: Arial, Helvetica, sans-serif; color: black
   }
.bootstrap-iso form button, .bootstrap-iso form button:hover{
   color: white !important;
   } 
.asteriskField{
   color: red;
   }
body{
   font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   background-color: thistle;
   color: rgb(39, 29, 29);
}
.form-group{
   padding: 20px;
   margin: 20px;
}
</style>
<body>
<div class="bootstrap-iso">
 <div class="container">
  <div class="row">
   <div class="col-md-12 col-sm-12 col-xs-12">
    <form class="form-horizontal" method="post">
     <div class="form-group ">
      <label class="control-label col-sm-2 requiredField" for="date">
       Set the calender here:
      </label>
      <div class="col-sm-10">
       <div class="input-group">
        <div class="input-group-addon">
         <i class="fa fa-calendar">
         </i>
        </div>
        <input class="form-control" id="date" name="date" placeholder="MM/DD/YYYY" type="text"/>
       </div>
      </div>
     </div>
     <div class="form-group">
      <div class="col-sm-10 col-sm-offset-2">
       <button class="btn btn-warning " name="submit" type="submit">
        Set the Calender
       </button>
      </div>
     </div>
    </form>
   </div>
  </div>
 </div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<script>
$(document).ready(function(){
var date_input=$('input[name="date"]');
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
date_input.datepicker({
format: 'mm/dd/yyyy',
container: container,
todayHighlight: true,
autoclose: true,
})
})
</script>
</body>  
</html>

Output:

Bootstrap Datepicker

Click on the input field to access the calendar. As shown below, you can change the date from the dropdown.

Bootstrap Datepicker

Methods that can be used with date-picker

.datepicker

It is used to initialize a datepicker.

remove

It takes no arguments and is used to remove the datepicker. It removes all the attached events, internally attached objects, and added HTML elements.

show

It takes no arguments and is used to show the datepicker.

hide

It takes no arguments and is used to hide the datepicker.

update

It takes no arguments and is used to update the datepicker with the new input value given by the user.

setStartDate

It takes a string for an argument, for example:

startDate (string)

It is used to set a new lower date limit on the datepicker and omit startDate.

It can provide an otherwise false value to unset the limit.

setEndDate

It takes a string for an argument, for example:

endDate (String)

It is used to set a new upper date limit on the datepicker and is used to omit endDate.

It can provide an otherwise false value to unset the limit.

setDaysOfWeekDisabled

It takes a string or an array for an argument, for example:

daysOfWeekDisabled (String|Array)

It is used to set the days of the week that should be disabled and is used to omit daysOfWeekDisabled.
It can provide an otherwise false value to unset the disabled days.


Related Topics

Bootstrap Tables

We can create different types of responsive and awesome bootstrap table like: striped , border etc. Bootstrap Basic Table We can create a basic bootstrap table by using its class .table. It has...

3 minutes read.

Bootstrap Glyphicons

Bootstrap Glyphicon is used to create different type of glyphicons It is used in the web project. It provides 260 Glyphicons from the Glyphivons Halflings set. There are various examples of...

1 minute read.

Text Shadows in CSS

Text shadows are created with the text-shadow CSS property. It takes a list of shadows separated by commas to be applied to the text and any of its styles. Each...

5 minutes read.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

Bootstrap Datepicker

What is a Bootstrap Datepicker? It is used to display a calendar with the date, month, and time from a dropdown menu. We will use an example to see how the date...

5 minutes read.

Bootstrap 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 minutes read.

Bootstrap Notification Bubble

What is a notification bubble? Bubbles are built into the Notification system. They float on top of the website or the button to indicate pending notifications. Bubbles can be expanded to reveal...

5 minutes read.

Bootstrap Input groups

Bootstrap 4 Input groups The input group is a component of Bootstrap 4, which is used to create interactive and stylish form controls. With the help of input groups, you can easily customize the input...

8 minutes read.

Bootstrap First Example

1) Add HTML5 doctype Before starting the example of Bootstrap, we should know about the some basic rules of Bootstrap. We have to add HTML5 doctype with lang element and CSS properties. <!DOCTYPE html>   <html lang="en">     <head>       <meta charset="utf-8">      </head>   </html> 2) Bootstrap...

2 minutes read.

Bootstrap 4 Grid Classes

Bootstrap 4 Grid Classes Extra-small Grid – In the extra-small grid system class, when you create the grid (columns), the columns will not be stacked on top of each other on...

8 minutes read.

Bootstrap Tabs and Pills

Bootstrap Menus Bootstrap menu is used to create different types of menu. It can created horizontal with its .list-inlineclass. <div class="container">       <h3>Example of Bootstrap Menu</h3>       <ul class="list-inline">         <li><a href="#">Home</a></li>         <li><a href="#">About</a></li>         <li><a href="#">Contact</a></li>         <li><a href="#">services</a></li>       </ul>     </div> Try Now Bootstrap Tabs Bootstrap tabl is look like is menu but there is some difference....

4 minutes read.

Bootstrap Images

Bootstrap 4 Images Bootstrap provides several classes for images to make them responsive and also helps to give some style to the images. Image Shapes Rounded Corners Bootstrap 4 offers .rounded class that makes the corners...

5 minutes read.

Bootstrap 4 Spinners

Bootstrap 4 offers spinner is a loading indicator that is used to display the loading state of any component or web page. The spinner is also known as a loader...

7 minutes read.

Difference between bootstrap.css and bootstrap-theme.css

The "bootstrap.css" uses to create a website with pre-existing designs and context. It uses basic Bootstrap classes like rows and columns with a CSS styling tool. The website is styled...

5 minutes read.

Bootstrap 4 Popover

Bootstrap 4 Popover Popover A popover is similar to the tooltip. The only difference between tooltip and Popover is that in the tooltip, the popup box appears when you move the cursor...

6 minutes read.

Bootstrap 4 Grid System

Bootstrap 4 Grid System The bootstrap 4 grid system is used to create a responsive website layout. The bootstrap 4 offers a mobile-first flexbox grid system that allows you to divide...

4 minutes read.

Bootstrap 4 Buttons

Bootstrap Buttons Bootstrap provides many custom button styles. These buttons are used in forms and dialog boxes for actions. Bootstrap offers various predefined classes for providing styles to buttons. There are many classes that are used...

7 minutes read.

Bootstrap Contact Us page

What is a “Contact Us” page? A “Contact Us” page is a web page available on the websites of various companies, organisations etc., for its users to contact the organisation or...

5 minutes read.

Bootstrap Wells

In Bootstrap, well are used to add a rounded border around an element. It is default some padding and gray background color. It is like a container that displays the content....

1 minute read.

Bootstrap 4 Carousel

Bootstrap 4 Carousel Bootstrap 4 offers a carousel component, which is also known as a slider or slideshow. The carousel is used for the dynamic representation of content using images with...

7 minutes read.