Bootstrap year picker example using datepicker js

Today now in this post i will talk about Bootstrap year picker example using datepicker js. In generally we are always use datepicker with the dd-mm-yyyy format but in sometimes we need to get only year value, Here i mean that select only the year so at that time we need to use the datepicker option as like as format, minViewMode etc so on that way we can make the datepicker into year picker for us.

Now in this example i will give an example of how can we can get year picker, so here i will use two option from datepicker function here one format and other minViewMode, by the default minViewMode is for datepicker, if we have to use 1 then it is for month picker and use 2 for year picker.

so let’s run the bellow example or we can see demo as well as:

Example:
<html lang="en">
<head>


    <title>Bootstrap - year picker only example</title>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>


</head>
<body>


<div class="container text-center">


     <h2>Bootstrap - year picker only example</h2>
     <input class="date-own form-control" style="width: 300px;" type="text">


  <script type="text/javascript">
      $('.date-own').datepicker({
         minViewMode: 2,
         format: 'yyyy'
       });
  </script>


</div>


</body>
</html>

Read Also : How to Create Custom Blade Directive in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →