Reputation: 147
I'm currently working on a project that makes heavy use of dates.
Is there anything inherently wrong with doing this:
var TodayPlusSeven = new Date(new Date().setDate(new Date().getDate() + 7));
I'm not an expert with JavaScript, but this seems to work. I'm not sure of the negative effects that doing something like this can have.
Thanks.
Upvotes: 0
Views: 219
Reputation: 74076
In your current code you create 3 Date
objects in the process. This is not necessary. You could just update one object to the respective day:
var TodayPlusSeven = new Date();
TodayPlusSeven.setDate( TodayPlusSeven.getDate() + 7 );
Upvotes: 1