I'm using Bootstrap 3 Datepicker here.
I want to change the default view of date picker to YEAR instead of DAYS, since I will use it for birth date selection.
I want to have like this as default.
How can I achieve it?
You can use the viewMode
option setting the 'year'
value. There is a sample on the official site and you can see the following code as example:
$('#datetimepicker1').datetimepicker({
viewMode: 'years',
format: 'DD/MM/YYYY',
defaultDate: moment('01/01/1990', 'DD/MM/YYYY'),
showClear: true
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<div class="form-group">
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" />
<span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
</div>
</div>
EDIT:
You can use defaultDate
to set a default date to the picker, so it shows the year that you prefer when it opens.