How to subtract days from a date in JavaScript

1 Answer

0 votes
function subtractDaysFromDate(days, date = new Date()) {
  	date.setDate(date.getDate() - days);

  	return date;
}

console.log(subtractDaysFromDate(3, new Date('2022-03-18')).toDateString());


  
/*
run:
  
"Tue Mar 15 2022"
  
*/

 



answered Mar 18, 2022 by avibootz

Related questions

2 answers 211 views
1 answer 146 views
1 answer 105 views
1 answer 139 views
139 views asked Mar 30, 2022 by avibootz
1 answer 138 views
1 answer 146 views
3 answers 334 views
...