-1

This is my html code:

<div class="input-group input-medium date date-picker"
    data-date=""
    data-date-format="yyyy-mm-dd"
    data-date-viewmode="years"
    data-date-minviewmode="months"
    data-date-end-date="+0d">
    <input name="water.month" type="text" value="${water?.month}" class="form-control" id="months">
    <span class="input-group-btn">
        <button class="btn btn-info" type="button"><i class="fa fa-calendar"></i></button>
    </span>
</div>

I want to show the previous month only in my calendar . How Can I do it?

Mehdi Dehghani
  • 10,970
  • 6
  • 59
  • 64
OUN Saif
  • 305
  • 1
  • 4
  • 20

1 Answers1

1

If I understand your question correctly, You want to display only one month (Previous Month). If so, Try this:

<div id='myDate'>
    <input type="text" type="text" class="form-control"/>
</div>

Javascript:

var now = new Date();
var prevMonthFirstDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() - 1 + 12) % 12, 1);
var prevMonthLastDate = new Date(now.getFullYear(), now.getMonth(), 0);
$('#myDate input').datepicker({
startDate: prevMonthFirstDate,
endDate: prevMonthLastDate
});

To understand how to get the first day of the month, have a look at this answer

Here is a JSFiddle

Mahmoud Ibrahim
  • 1,703
  • 15
  • 15