Reputation: 309
I assigned the weekEnd as the current end of the week like this
this.weekEnd = new Date(this.currentDate.setDate(end));
Next, what I want is to give a new value to the weekEnd which is the weekEnd + 7 days. I've done it like below but I can't assign the new value to the weekEnd because the right side returns a Number and not date.
this.weekEnd = this.weekEnd.setDate(this.weekEnd.getDate() + 7);
If you guys have any idea how I can do it I would appreciate it. Thanks a lot!
Upvotes: 1
Views: 1011
Reputation: 28246
Just use the .setDate()
method without the assignment:
this.weekEnd.setDate(this.weekEnd.getDate() + 7);
.setDate()
does two things:
In your code you assigned this number to the variable that would have held the correct date anyway.
Upvotes: 3
Reputation: 2276
Try this. It will return 15th Jun and 21st June. If you remove +1 then it will start from sunday. To start from monday you have to add 1.
let current = new Date;
let firstday = new Date(current.setDate(current.getDate() - current.getDay()+1));
let lastday = new Date(current.setDate(current.getDate() - current.getDay()+7));
Upvotes: 0