How to get the date of the close previous sunday in Node.js

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-01-11')).toDateString());

  
  
  
  
/*
run:
  
Sun Jan 09 2022
  
*/

 



answered Apr 5, 2022 by avibootz
...