1

I would like to deduct a few days from today's date.

"2020-01-24" minus 1 day --> "2020-01-23"

And if I subtract 24 days, I want to get "2019-12-31".

THANKS!!!

G-EA
  • 337
  • 7
  • 17
  • Does this answer your question? [How to subtract days from a plain Date?](https://stackoverflow.com/questions/1296358/how-to-subtract-days-from-a-plain-date) – pilchard Feb 01 '23 at 23:58

1 Answers1

5

You can do it by Date.prototype.setDate.

let d = new Date("2020-01-24");

d.setDate(d.getDate() - 5); // subtract 5 days

console.log(d);

console.log(d.toISOString().split("T")[0]); // 2020-01-19
Akshay Bande
  • 2,491
  • 2
  • 12
  • 29