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 318 views
1 answer 234 views
1 answer 208 views
1 answer 223 views
223 views asked Mar 30, 2022 by avibootz
1 answer 227 views
1 answer 217 views
3 answers 476 views
...