Reputation: 687
I am using the following code to display the year range:
$('.date-own').datepicker({
format: " yyyy",
viewMode: "years",
minViewMode: "years",
autoclose: true,
startView: 2,
yearRange: '1950:2011'
});
But the range is not coming.
How can I solve this since I only need the year from 1950 to 2010 only?
Upvotes: 1
Views: 2981
Reputation: 28522
In your datepicker you can use startDate
and endDate
and there you can specify how many year from now i.e : 1950-2021 = -71y
to set startDate and same for other .
Demo Code :
$('.date-own').datepicker({
format: "yyyy",
viewMode: "years",
updateViewDate: true,
minViewMode: "years",
autoclose: true,
startView: 2,
defaultViewDate: {
year: '1950'
},
startDate: '-71y', //2021 -1950
endDate: '-10y' //2021-2011
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.css" />
<input type="text" class="date-own">
Upvotes: 1