You can get the previous Monday by getting the Monday of this week and subtracting 7 days. Sunday will be the day before, so:
var d = new Date(); // set to Monday of this week d.setDate(d.getDate() - (d.getDay() + 6) % 7); // set to previous Monday d.setDate(d.getDate() - 7); // create new date of day before var sunday = new Date(d.getFullYear(), d.getMonth(), d.getDate() - 1);
On 2012-12-03 I get:
Mon 26 Nov 2012 Sun 25 Nov 2012
Is this what you want?
// Or new date for the following Sunday var sunday = new Date(d.getFullYear(), d.getMonth(), d.getDate() + 6);
which gives
Sun 02 Dec 2012
In general, you can manipulate date objects by adding and subtracting years, months, and days. The object will process negative values automatically, for example.
var d = new Date(2012,11,0)
A date will be created for 2012-11-30 (noting that the months are zero, so 11 is December). Also:
d.setMonth(d.getMonth() - 1); // 2012-10-30 d.setDate(d.getDate() - 30); // 2012-09-30
source share