-1

I need after date subtraction return date in string format yyyy-mm-dd

const date = new Date();
const diff = date.setDate( date.getDate() - 10 );

adding toISOString() doesnt works because it's not a fuction

3 Answers3

0

Edit: Simpler solution (thank you, @Ivar). You can use toISOString directly on date.

const date = new Date();

date.setDate( date.getDate() - 10 );

const iso_date = date.toISOString();
Emil Karlsson
  • 1,000
  • 1
  • 7
  • 16
0
const d = new Date();

const result = d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate()

console.log(result)
0
const date = new Date();
const diff = date.setDate( date.getDate() - 10 );
const d = new Date(diff);
const result = d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate();