Arrangement of JQuery Dates

0

Someone who can help me make an arrangement of dates, with JQuery.

I want to make an arrangement of dates "approximately 6 or more", from a given date, the date will be assigned by the user in an input, once the user selects the date: var fech = $("#fecha").val(); , for example '2017/11/22' create an arrangement

fechas = [{'2017/11/23},{'2017/11/24},{'2017/11/25},{'2017/11/27},{'2017/11/28},{'2017/11/29}];

besides omitting the dates of Sunday. Someone who can help me with it? I have no idea how to do it.

    
asked by Soldier 22.11.2017 в 20:36
source

1 answer

1

Look at this example.

In the event change of input the date is captured from the value and a day is added.

From there, it enters a loop in which it is added one day after each cycle and ends when the array fechas has 6 elements.

Inside the loop, it is checked if the calculated day is Sunday and, if it is not, it is added to the array.

$(function(){
  $('#fecha').change(function(){
    var date = new Date($(this).val());
    date.setDate(date.getDate() + 1);
    if (date){
      var fechas = [];
      for (;fechas.length < 6; date.setDate(date.getDate() + 1)){
        if (date.getDay() > 0)
          fechas.push(date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());
      }
      console.log(fechas);
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" id="fecha">
    
answered by 22.11.2017 / 20:56
source