Ding Luo Ding Luo - 7 months ago 96
Javascript Question

Return last day of last month when using Bootstrap Datepicker to select month

I want to use Bootstrap datepicker to just select month, but it always return the last day of last month, for example, if I select Jan. 2016, it returns 12-31-2015, I want to get the first day of the month I selected.

My code:

if ($(this).hasClass('month-only')) {
$(this).prop('readonly', true).datepicker({
format: 'yyyy-mm',
viewMode: 'months',
minViewMode: 'months',
autoclose: true
});
}

Rik Rik
Answer
$('#input').datepicker({
    minViewMode: 1,
    format: 'yyyy-mm-dd',
    autoclose: true
});

should work https://jsfiddle.net/z56j2eod/3/

or if you want only yyyy-mm your code just works https://jsfiddle.net/z56j2eod/4/

Comments