1

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?

1 Answer 1

1

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">

Sign up to request clarification or add additional context in comments.

3 Comments

I need one more favor also, do we active the 1950 year by default and only show the start date and end date only in the calendar
See , i have update . But, not sure about second issue as year are already disabled .
thanks and I find the solution to the second issue using CSS. .datepicker table tr td span.disabled, .datepicker table tr td span.disabled:hover { display:none; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.