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 204 views
1 answer 142 views
1 answer 97 views
1 answer 135 views
135 views asked Mar 30, 2022 by avibootz
1 answer 131 views
1 answer 140 views
3 answers 322 views
...