Answers for "how to get all dates of last week in javascript"

3

Get First Day and last day of week javascript

var curr = new Date; // get current date
var first = curr.getDate() - curr.getDay(); // 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(curr.setDate(first)).toUTCString();
var lastday = new Date(curr.setDate(last)).toUTCString();

firstday
"Sun, 06 Mar 2011 12:25:40 GMT"
lastday
"Sat, 12 Mar 2011 12:25:40 GMT"
Posted by: Guest on January-02-2022
2

javascript get date of last monday

let prevMonday = new Date();
prevMonday = new Date(prevMonday.setDate(prevMonday.getDate() - (prevMonday.getDay() + 6) % 7));
// sets the date object to last Monday, if the current day is Monday,
// set it to the current date

prevMonday = new Date(prevMonday.setHours(0,0,0)); // sets hours, mins, secs to 0
Posted by: Guest on March-08-2021

Code answers related to "how to get all dates of last week in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language