How to get the date of the close previous sunday in TypeScript

1 Answer

0 votes
function getClosePreviousSundayDate(date = new Date()) {
    const ClosePreviousSunday = new Date(date);
 
    ClosePreviousSunday.setDate(ClosePreviousSunday.getDate() - ClosePreviousSunday.getDay());
 
    return ClosePreviousSunday;
}
 
console.log(getClosePreviousSundayDate(new Date('2022-02-10')).toDateString());
 
   
   
   
   
/*
run:
   
"Sun Feb 06 2022" 
   
*/

 



answered Apr 5, 2022 by avibootz
...