I am trying to implement previous/next two weeks to my scheduler, but it is not working correctly.. This is what I try:
this.datesArray = [];
const currentDate: Date = new Date(this.startDate);
const lastDate: Date = new Date(this.endDate);
currentDate.setDate(currentDate.getDate() - 14);
lastDate.setDate(currentDate.getDate() + 30);
while (currentDate < lastDate) {
// var newDate: Date = new Date(currentDate);
this.datesArray.push(currentDate.toDateString());
currentDate.setDate(currentDate.getDate() + 1);
}
Every click I trigger this code, but there is the following issue. First 2 times it works great, but 3rd time I click next, last date.SetDate bugs out, it addds 60 days instead of 30. Here is what I mean for the previous week:
It shows current date Feb 22, but then adds 30 days, and it shows Apr 21 somehow..
Anyone had similar issues?