I am using the following code to display only the years:
$(\"#datepicker\").datepicker( {viewMode: \"years\", minViewMode: \"years\"});
but inp
For bootstrap datetimepicker
, assign decade
value as follow:
$(".years").datetimepicker({
format: "yyyy",
startView: 'decade',
minView: 'decade',
viewSelect: 'decade',
autoclose: true,
});
For bootstrap 3 datepicker. (Note the capital letters)
$("#datetimepicker").datetimepicker( {
format: "YYYY",
viewMode: "years"
});
format: "YYYY"
Should be capital instead of "yyyy"
always year for bootstrap 3 datetimepicker https://eonasdan.github.io/bootstrap-datetimepicker/
$('#year').datetimepicker({
format: 'YYYY',
viewMode: "years",
});
$("#year").on("dp.hide", function (e) {
$('#year').datetimepicker('destroy');
$('#year').datetimepicker({
format: 'YYYY',
viewMode: "years",
});
});
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"
});
$("#year").datepicker( {
format: "yyyy",
viewMode: "years",
minViewMode: "years"
}).on('changeDate', function(e){
$(this).datepicker('hide');
});