date - Days are not added properly with momentJS in JavaScript -
i have code want next 15 days start date
var fortnightstart = moment("15 04 2015", "dd mm yyyy"); (var = 1; <= 15; i++) { dates.push(fortnightstart.add(i, "days").format("d mmm")); } console.log(dates);
this output
["16 apr", "18 apr", "21 apr", "25 apr", "30 apr", "6 may", "13 may", "21 may", "30 may", "9 jun", "20 jun", "2 jul", "15 jul", "29 jul", "13 aug"]
i don't know why missing few days.
on every iteration add i
days initial date - keeps accumulating (+1, +2, +3 etc). need add not i
1
fortnightstart
.
var fortnightstart = moment("15 04 2015", "dd mm yyyy"); (var = 1; <= 15; i++) { // 1, not dates.push(fortnightstart.add(1, "days").format("d mmm")); } console.log(dates);