How to get first and last day of the current week in JavaScript

1 Answer

0 votes
const today = new Date(); 

const first = today.getDate() - today.getDay(); 
const last = first + 6; 

const firstday = new Date(today.setDate(first)).toUTCString();
const lastday = new Date(today.setDate(last)).toUTCString();

console.log(firstday);
console.log(lastday);
 
  
   
  
/*
run:
  
"Sun, 27 Mar 2022 16:55:18 GMT"
"Sat, 02 Apr 2022 16:55:18 GMT"
  
*/

 



answered Mar 31, 2022 by avibootz

Related questions

...