tags:

views:

433

answers:

3

Does anyone know how can I get next week date based on this week date? example if I have this thursday date (25/6/2009) how can I use javascript to get next thursday date (2/7/2009)?

+4  A: 
Date.prototype.addDays = function (d) {
    if (d) {
        var t = this.getTime();
        t = t + (d * 86400000);
        this.setTime(t);
    }
};

this_week.addDays(7);
razzed
I like it...! +1
Cerebrus
I would let the date prototype alone, though.
subtenante
Why leave the date prototype alone?
razzed
You never know which library you'll end up using. You may come to use something defining a addDays method for computing working days. Then you scratch your head.
subtenante
+3  A: 
var firstDay = new Date("2009/06/25");
var nextWeek = new Date(firstDay.getTime() + 7 * 24 * 60 * 60 * 1000);

You can also look at DateJS if you like "fluent" APIs.

Matthew Flaschen
+3  A: 
function nextweek(){
    var today = new Date();
    var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7);
    return nextweek;
}
subtenante
Nice - The function is self-documenting and works with edge cases such as leap seconds.
l0b0