How to get the date of the next Friday using TypeScript

1 Answer

0 votes
function getNextFridayDate(date = new Date()) {
  	const today = new Date(date.getTime());

  	const nextFriday = new Date(
    	today.setDate(today.getDate() + ((7 - today.getDay() + 5) % 7 || 7),
      ),
  	);

  	return nextFriday;
}

console.log(getNextFridayDate(new Date()).toDateString());


  
  
  
  
/*
run:
  
"Fri Apr 15 2022"
  
*/

 



answered Apr 2, 2022 by avibootz

Related questions

1 answer 137 views
1 answer 127 views
1 answer 135 views
1 answer 161 views
1 answer 152 views
1 answer 146 views
...