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
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
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();
const d = new Date();
const result = d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate()
console.log(result)
const date = new Date();
const diff = date.setDate( date.getDate() - 10 );
const d = new Date(diff);
const result = d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate();