How to get first and last day of the current week in Node.js

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, 10 Apr 2022 16:35:07 GMT" 
"Sat, 16 Apr 2022 16:35:07 GMT" 
  
*/

 



answered Mar 31, 2022 by avibootz

Related questions

1 answer 179 views
1 answer 148 views
1 answer 135 views
1 answer 125 views
1 answer 144 views
1 answer 138 views
...