Obtain a date with a certain frequency [closed]

0

I need your help, I have a date that is variable, at that date you will add a frequency example 15 days , I would like from the date given example:
12 / 03/2018
make a count of your established frecuncia that therefore summary 15 days
and from that would throw the following date which would be:               03/27/2018 .
And in the same way I would like you to do another sum of other 15 days and so on.
NOTE: I am working with php and javaScript

    
asked by Eddy Olvera 12.03.2018 в 19:08
source

1 answer

0

Here is an example using the library Moments.js , and using the function Javascript setInterval to create the iteration of the sum.

As you noticed, I put a counter so that at some point the iteration ends and it does not run forever.

var fecha = moment("12/03/2018","DD/MM/YYYY");
var cont=0;

var loop = setInterval(function(){
  sumarDias()
  
  if(cont == 5)
    clearInterval(loop);
    
  cont++;
}, 1000);


function sumarDias(){
  fecha.add(15, 'days')
  console.log(fecha.format("DD-MM-YYYY"));
}
<script src="https://momentjs.com/downloads/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
answered by 12.03.2018 / 20:05
source