Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
145
rated 0 times [  152] [ 7]  / answers: 1 / hits: 58824  / 10 Years ago, mon, march 3, 2014, 12:00:00

I searched for this question and found there is a no answer on Stackoverflow.. So I decided to answer it...



This question helps if you need to get the start/end of next/last week with Monday as start of week.


More From » jquery

 Answers
9

I used moment js for this ... u can get it from here



     /*
all functions return moment() object.. <br>
GetNextWeekStart().format('DD/MM/YYYY') to get 24/02/2014
*/

function GetNextWeekStart() {
var today = moment();
//edited part
var daystoMonday = 0 - (today.isoWeekday() - 1) + 7;
var nextMonday = today.subtract('days', daystoMonday);

return nextMonday;
}

function GetNextWeekEnd() {
var nextMonday = GetNextWeekStart();
var nextSunday = nextMonday.add('days', 6);

return nextSunday;
}

function GetLastWeekStart() {
var today = moment();
var daystoLastMonday = 0 - (1 - today.isoWeekday()) + 7;

var lastMonday = today.subtract('days', daystoLastMonday);

return lastMonday;
}

function GetLastWeekEnd() {
var lastMonday = GetLastWeekStart();
var lastSunday = lastMonday.add('days', 6);

return lastSunday;
}

[#72196] Saturday, March 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mireyag

Total Points: 73
Total Questions: 107
Total Answers: 85

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
mireyag questions
Sun, Aug 15, 21, 00:00, 3 Years ago
Wed, Dec 16, 20, 00:00, 3 Years ago
Tue, Sep 1, 20, 00:00, 4 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
;