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

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, 03 Apr 2022 16:59:07 GMT" 
"Sat, 09 Apr 2022 16:59:07 GMT" 
  
*/

 



answered Mar 31, 2022 by avibootz

Related questions

...