Answer the question
In order to leave comments, you need to log in
How to get the date of the next Saturday?
How to get the date of the nearest future Saturday? That is, for example, the user logged in today and I need to determine that the date is the next Saturday 15.12
.
Answer the question
In order to leave comments, you need to log in
function getDateOfNearestDay(day, date = new Date()) {
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + ((7 + day - date.getDay()) % 7));
}
const dateOfNearestSaturday = getDateOfNearestDay(6);
function getSaturday() {
var today = new Date().getUTCDay();
var diff = 6 - today;
if ([-1, 0].includes(Math.sign(diff))) {
return new Date(new Date().setUTCDate(13 - today));
}
return new Date(new Date().setUTCDate(diff));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question