Bootstrap Year Picker using Datepicker JS Example
Generally we are use datepicker with dd-mm-yyyy format but sometimes we require to get only year, i mean select only year at that time we need to use datepicker option like format, minViewMode etc that way we can make datepicker into year picker for us.
In this example i give you how can you get year picker, so i use two option from datepicker function one format and other minViewMode, by default minViewMode is for datepicker, if you use 1 then it is for month picker and 2 for year picker, so let's run bellow example or you can see demo as well:
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>
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular Bootstrap Carousel Example
- Bootstrap Datepicker Disable Specific Dates Example
- Bootstrap Datepicker Disable Saturday and Sunday Example
- Bootstrap Multiselect Dropdown in Popup Example
- Laravel Notification Alert using Bootstrap Notify Plugin Example
- Laravel Create Bootstrap Contact US Form Example
- AngularJS Tooltip using UI Bootstrap tpls HTML Example
- Bootstrap Dynamic Autocomplete search using Typeahead JS
- Bootstrap Datepicker Change Date Format Example
- Bootstrap Colorpicker Example Code
- Bootstrap Timepicker using Datetimepicker JS Example
- JQuery Delete Confirm Modal using Bootbox Example
- How to Use Collapse Example in Bootstrap?
- How to Add Dialog Box in Bootstrap?