Bootstrap year picker example using datepicker js plugin

Bootstrap year picker example using datepicker js plugin

In this post we will give you information about Bootstrap year picker example using datepicker js plugin. Hear we will give you detail about Bootstrap year picker example using datepicker js pluginAnd how to use it also give you demo for it if it is necessary.

Bootstrap year picker example using datepicker js plugin

In this tutorial, you will know how to use year picker in your form using Bootstrap datepicker plugin.

In my last post, i told you about datepicker js plugin which is a simple jquery blugin built with bootstrap-datepicker.js to add flexible datepicker field to your form.

There are various option available with datepicker.

You need to pass extra option minViewMode with datepicker method that is used to set minimum limit for the view mode.

To get year picker you can set value of minViewMode either string ‘years’ or number value 2.

If you need to get month picker by year you need to use minViewMode:1 with format: 'mm-yyyy'.

See the given example :

  1. <html>
  2. <head>
  3. <title>Bootstrap year picker example using datepicker js plugin</title>
  4. <linkhref="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"rel="stylesheet">
  5. <linkhref="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css"rel="stylesheet">
  6. <scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
  7. <scriptsrc="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  8. <scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script></head>
  9. </head>
  10. <body>
  11. <strong>Year Picker :</strong><inputclass="form-control"type="text"placeholder="click to show datepicker"id="example1">
  12. <scripttype="text/javascript">
  13. // When the document is ready
  14. $(document).ready(function () {
  15. $('#example1').datepicker({
  16. minViewMode: 'years',
  17. autoclose: true,
  18.             format: 'yyyy'
  19. });
  20. });
  21. </script>
  22. </body>
  23. </html>
<html>
    <head>
     <title>Bootstrap year picker example using datepicker js plugin</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>
    
    </head>
    <body> 
       
       <strong>Year Picker :</strong> <input   type="text" placeholder="click to show datepicker"  id="example1">
       
        <script type="text/javascript">
            // When the document is ready
            $(document).ready(function () {
                
                $('#example1').datepicker({
                    minViewMode: 'years',
                    autoclose: true,
              format: 'yyyy'
                });  
            
            });
        </script>
 </body>
 </html>

To get month picker use following script :

  1. $(document).ready(function () {
  2. $('#example1').datepicker({
  3. minViewMode: 1,
  4. autoclose: true,
  5. format: 'mm-yyyy'
  6. });
  7. });
 $(document).ready(function () {
    $('#example1').datepicker({
           minViewMode: 1,
           autoclose: true,
           format: 'mm-yyyy'
    });  
            
});


Bootstrap datepicker example text input with specifying date format

Show Demo

Label :

HTML

jQuery

How To

CSS

Web Development

Bootstrap

JavaScript

Hope this code and post will helped you for implement Bootstrap year picker example using datepicker js plugin. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  34  =  40

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US