Select from a previous month forward using bootstrap datepicker

0

Hi, I am working with Bootraps DatePicker, I have managed to select months, as I could do so that the past months are disabled except one month prior to the current month, so it is selected from the previous month.

$('#mescierre').datepicker({
                format: "mm-yyyy",
                startView: "months", 
                minViewMode: "months",
                autoclose: true,locale:'es', language: 'es'
       });
  

link

    
asked by Eduardo Palomino 22.06.2017 в 00:39
source

1 answer

0

It's in the documentation: link

Used: startDate as follows:

$('#mescierre').datepicker({
            format: "mm-yyyy",
            startDate: "01/01/2017",
            startView: "months", 
            minViewMode: "months",
            autoclose: true,locale:'es', language: 'es'
   });

Edit

Now to play with the dates:

var ahora = new Date();
var d = ahora.getDate();
var m = ahora.getMonth() +1; //Considerando que Enero = 0 (donde inicia)
var y = ahora.getFullYear();
console.log( d+" "+m+" "+y); 21 6 2017

As you will need from the previous month,

var ahora = new Date();
var primerDiaDelAnteriorMes = new Date(ahora.getFullYear(), ahora.getMonth() - 1, 1);
console.log(primerDiaDelAnteriorMes); //Date 2017-05-01T07:00:00.000Z
//Ahora para convertirlo en algo que sea compatible con el parámetro esperado:
var fechaCorta = (primerDiaDelAnteriorMes.getMonth() + 1) + '/' + primerDiaDelAnteriorMes.getDate() + '/' +  primerDiaDelAnteriorMes.getFullYear();
console.log(fechaCorta); // Nos da como resultado: 5/1/2017

Now with the aforementioned, we are finishing up the rubik cube: D

$('#mescierre').datepicker({
        format: "mm-yyyy",
        startDate: "'"+fechaCorta+"'",
        startView: "months", 
        minViewMode: "months",
        autoclose: true,locale:'es', language: 'es'
});
    
answered by 22.06.2017 в 01:04