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)?
10 Answers
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.

- 1,398
- 2
- 17
- 36

- 278,309
- 50
- 514
- 539
-
1@etienne, did you try datejs? I'm just curious, I haven't tested it with daylight-savings specifically. – Matthew Flaschen Oct 30 '12 at 10:37
-
Not yet. But I am currently fighting with DST - since we changed this week-end :( – etienne Oct 30 '12 at 10:51
-
Using the Date constructor to parse strings is not a good idea. – RobG Jun 12 '15 at 02:50
-
I made a stupid typo (* 25 not * 24) and was sitting there for ages, trying to work out why my time had moved forward by 7 hours... – Tim Sep 14 '16 at 02:36
function nextweek(){
var today = new Date();
var nextweek = new Date(today.getFullYear(), today.getMonth(), today.getDate()+7);
return nextweek;
}

- 45,516
- 29
- 93
- 118
-
Nice - The function is self-documenting and works with edge cases such as leap seconds. – l0b0 Jun 22 '09 at 07:20
-
Nice work. with a slight adaption you can find a day of the week (i.e.: next thursday). ad to the last argument, today.getDate() - today.getDay() + 7 + 4 (that works for thursday) – Lathan Jun 24 '11 at 19:46
-
5This might generate some invalid dates however, which may or may not work, depending on how clever the target JS engines Date() functions are. For instance a week after 30 august 2013 will be 37 august 2013 , which is invalid. – Shayne Aug 30 '13 at 01:12
-
1Check the fiddle that I wrote to see if it works or not on a given browser: http://jsfiddle.net/kymg264r/ – Savas Vedova Dec 09 '14 at 07:54
function dateObject.getNextWeekDay returns the next weekday after the object's own date.
Date.prototype.getNextWeekDay = function(d) {
if (d) {
var next = this;
next.setDate(this.getDate() - this.getDay() + 7 + d);
return next;
}
}
var now = new Date();
var nextMonday = now.getNextWeekDay(1); // 0 = Sunday, 1 = Monday, ...
var secondNextMonday = new Date(nextMonday).getNextWeekDay(1);
console.log('Next Monday : ' + nextMonday);
console.log('Second Next Monday : ' + secondNextMonday);
-
-
this is destructive, it updates the argument. http://stackoverflow.com/questions/1090815/how-to-clone-a-date-object-in-javascript – Karoly Horvath Aug 06 '13 at 11:55
-
2And pollutes the Date prototype - see http://programmers.stackexchange.com/questions/104320/why-is-extending-the-dom-built-in-object-prototypes-a-bad-idea – tuomassalo Aug 09 '13 at 08:07
-
Date.prototype.addDays = function (d) {
if (d) {
var t = this.getTime();
t = t + (d * 86400000);
this.setTime(t);
}
};
this_week.addDays(7);

- 2,653
- 25
- 27
-
2
-
1
-
4You 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. – glmxndr Jun 22 '09 at 06:39
-
I agree, but I prefer the elegance of extending `Date`s in a proper object-oriented manner; and control which libraries I use. – razzed Aug 06 '14 at 16:28
-
This is not much of a problem anymore in modern development with private modules. – cchamberlain Jun 01 '15 at 03:07
Function that returns next weekdaay:
function getNextWeekDay (startDate, dayOfWeek){
var dayOffset = dayOfWeek > startDate.getDay()
? dayOfWeek - startDate.getDay()
: dayOfWeek - startDate.getDay() + 7;
startDate.setDate(startDate.getDate() + dayOffset);
return startDate;
}
var now = new Date();
var nextMonday = getNextWeekDay(new Date(),1); // 0 = Sunday, 1 = Monday, ...
var nextSaturday = getNextWeekDay(new Date(),6);
var nextSunday = getNextWeekDay(new Date(),0);
var secondNextMonday = getNextWeekDay(new Date(now.getTime() + ( 7 *24 * 60 * 60 * 1000)),1);
alert(nextMonday+ '- '+nextSaturday+ '- '+nextSunday+ '- '+secondNextMonday);

- 1
- 1

- 333
- 3
- 7
const getDateAfterWeek = (week) => {
let today = new Date();
const nextweek = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate() + 7 * week,
);
return nextweek;
}

- 5,600
- 2
- 38
- 44

- 54
- 6
-
2Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Aug 04 '20 at 09:42
An even more straightforward solution is
let nextWeek = new Date()
nextWeek.setDate(nextWeek.getDate() + 7)
Note that it preserves the current time of day.

- 198
- 3
- 5
this is my solution.
var today = new Date; // get current date
var first = today.getDate() - today.getDay() + 1 + 7; // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6
var firstday = new Date(today.setDate(first));
var lastday = new Date(today.setDate(last));
console.log(firstday, lastday);

- 478
- 7
- 10
I got it this way:
public nextAnswerDay(answerDay) {
const now = new Date().getDay();
let distance = 0
if (answerDay < now) {
distance = 7 - (now - answerDay);
} else {
distance = Math.abs(now - answerDay);
}
let nextAnserDay = new Date();
nextAnserDay.setDate(nextAnserDay.getDate() + distance);
return nextAnserDay;
}

- 2,377
- 7
- 20
- 39

- 1
- 2
There's a fundamental problem with most of the other answers. That is, they don't take into consideration that a different time zone may have a different date, especially if this javascript will be a webpage script.
To deal with this, the date object should be manipulated using the UTC methods. All code should use UTC time to allow the date to return an appropriate local time.
Note: This function returns the upcoming day. Furthermore, it returns today if you're looking for Monday and that's today. (See this answer for the difference between next Monday and the upcoming / this Monday: https://english.stackexchange.com/a/3844)
Without further ado here is the code. As per MDN, the weekday parameter is UTC day 0-6.
function getUpcomingUTCWeekDay(weekday) {
let date = new Date();
let currentDay = date.getUTCDay();
if (currentDay > weekday) {
let daysTilNextWeek = 7 - currentDay;
date.setUTCDate(date.getUTCDate() + daysTilNextWeek);
currentDay = date.getUTCDay();
}
if (currentDay === weekday) {
return date;
}
if (currentDay < weekday) {
date.setUTCDate(date.getUTCDate() + (weekday - currentDay));
return date;
}
return date;
}

- 1,908
- 13
- 33