Bootstrap year picker example using datepicker js

By Hardik Savani | July 6, 2016 | | 3363 Viewer | Category : Bootstrap


Share this post:

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>