Ding Luo
Ding Luo

Reputation: 13

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
      });
    }

Upvotes: 1

Views: 2465

Answers (3)

M.Kazemi
M.Kazemi

Reputation: 1

$(".of-date").persianDatepicker({ inline: false, altField: '#ofDate', altFormat: 'YYYY/MM/DD', dayPicker: { enabled: false } });

Upvotes: 0

FittyFrank
FittyFrank

Reputation: 134

Hmm, the above answer doesn't set the date to the end of the month in the jsfiddle link. If anyone is still looking for an answer, I provided an updated answer on this post here: bootstap Datepicker : set value as last day of the month not working

You need to use the 'changeDate' event and the the 'update' method to set the date how you would like to avoid the default first day of month.

Upvotes: 2

Rik
Rik

Reputation: 60

$('#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/

Upvotes: 0

Related Questions