2

I am running Bootstrap 3.3.6 (latest) and Datepicker plugin 1.6.0 (latest).

I want the date box to only accept and display year between a certain range (in my current case 2014, 2015, and 2016).

I have this customization in place:

$('#my-container .my-class').datepicker({
  //format: " yyyy", // does not work
  minViewMode: "years",
  maxViewMode: "years",
  startDate: '01/01/2014',
  endDate: new Date(),
  startView: "year" //does not work
});

Is it possible to limit the input and display to just a 4-digit year?

1 Answer 1

3

Try this solution :

$('.datepicker').datepicker({
    autoclose: true,
    format: " yyyy",
    viewMode: "years", 
    minViewMode: "years",
    startDate: '2014',
    endDate: new Date(),
});

See JsFiddle. I hope it works for you, thanks.

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

2 Comments

Excellent @ShadyAlset. Worked perfectly. Greatly appreciate the solution !
External resouces link of jsFiddle may be expired. It is not working now.

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.