Reputation: 4581
http://jsfiddle.net/e31m02L9/2/
How can I have DateTimePicker pick a month instead of a date and time? (So the value is YYYY-MM
)
Looking at online documentation I was told to use startView
:
$('#datetimepickerday').datetimepicker({
startView: "month"
});
But it gives the following error:
Upvotes: 0
Views: 2158
Reputation: 31502
Yes, you have to use viewMode
instead of startView
and set format
option to YYYY-MM
. If you specify format: 'YYYY-MM'
with eonasdan datetimepicker the default behaviour is to show the months dropdown (no need to explicitly set viewMode
)
Here a working example:
$('#datetimepicker1').datetimepicker({
format: 'YYYY-MM',
viewMode: 'months'
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/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.17.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<div class="input-group date" id="datetimepicker1">
<input type="text" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
Upvotes: 1