'jquery ui datepicker select only current and previous month

Hello folks and thanks for reading.

I am trying to implement jquery ui datepicker and what i am trying to do is the following ;

  1. Allow the user to selct only the current and previous months
  2. The full month should be selectable( i used minDate:-1m , but this allows you to select only certain days in the month not all of the dates)

This is the configuration i have so far , any input would be much appreshiated :

'options'=>array(
                        'dateFormat'=>'yy-mm-dd',
                        'defaultDate'=>$model->dataCaricamento,
                        'showAnim'=>'fold',
                        'showButtonPanel'=>false,
                        'changeYear'=>false,
//                          'monthRange'=>'-1:+1',
//                          'defaultDate'=>'+0',
//                            'maxDate'=>'+1m',
//                            'minDate'=>'-1m',
//                            'selectOtherMonths'=>false,
//                            'showOtherMonths'=>false,
//                             'numberOfMonths'=>[ 1, 2 ],
//                             'stepMonths'=>0
                              'changeMonth'=> true,
//        'minDate'=> '-1m',
//        'maxDate'=> '0',   //add this


Solution 1:[1]

Try

Create required date objects and set them as min and max

var currentTime = new Date() 
var minDate = new Date(currentTime.getYear(), currentTime.getMonth()-1); //previous month
var maxDate =  new Date(currentTime.getFullYear(),currentTime.getMonth()); // this month
$( "#datepicker" ).datepicker({ 
minDate: minDate, 
maxDate: maxDate 
});

http://api.jqueryui.com/datepicker/#option-minDate

Solution 2:[2]

$( "#datepicker" ).datepicker({ minDate: '-30', maxDate: '0' });

Solution 3:[3]

you can use it, this is working correctly.. you can also use it for multiDatesPicker..

var currentTime = new Date(); var minDate = new Date(currentTime.getFullYear(), currentTime.getMonth()-1); //previous month var maxDate = new Date(currentTime.getFullYear(),currentTime.getMonth()); // this month $("#your_id").datetimepicker({ dateFormat: "yy-mm-dd", closeOnDateSelect: true, timepicker: false, scrollMonth: false, minDate: minDate, maxDate: 0 });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Nikki
Solution 3