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

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-03-09')).toDateString());

  
  
  
  
/*
run:
  
"Sun Mar 06 2022"
  
*/

 



answered Apr 5, 2022 by avibootz
edited Apr 5, 2022 by avibootz

Related questions

1 answer 150 views
1 answer 149 views
1 answer 138 views
1 answer 138 views
1 answer 146 views
1 answer 187 views
...