How to subtract days from a date in TypeScript

1 Answer

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

  	return date;
}

console.log(subtractDaysFromDate(5, new Date('2022-03-19')).toDateString());


  
/*
run:
  
"Mon Mar 14 2022" 
  
*/

 



answered Mar 18, 2022 by avibootz
...