How display only years in input Bootstrap Datepicker?
Try this
$("#datepicker").datepicker({ format: "yyyy", viewMode: "years", minViewMode: "years"});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" rel="stylesheet"/><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/><input type="text" id="datepicker" />
$("#datepicker").datepicker( { format: " yyyy", // Notice the Extra space at the beginning viewMode: "years", minViewMode: "years"});
For bootstrap datetimepicker
, assign decade
value as follow:
$(".years").datetimepicker({ format: "yyyy", startView: 'decade', minView: 'decade', viewSelect: 'decade', autoclose: true,});
$("#year").datepicker( { format: "yyyy", viewMode: "years", minViewMode: "years"}).on('changeDate', function(e){ $(this).datepicker('hide');});