I have this prop this.props.SearchDate
coming in as a format like this 2016-03-31
(yyyy-MM-DD)
If I do
let date = new Date(new Date().setDate(new Date().getDate() - 1)).toISOString().substring(0,10);
console.log(date)
I get the correct yesterday date, but if I do
let date = new Date(new Date().setDate(new Date(this.props.SearchDate).getDate() - 1)).toISOString().substring(0,10);
console.log(date)
I get 2019-04-29
If I remove -1, then it gets the date 30. Though actually since current date there is 31 then -1 should make day before 30.
All I need from date is to give it yyyy-mm-dd some date, and get exactly 1 date before than that. Can anyone see the problem here? This seem to be explained here: Why does js subtract a day from a Date object with a certain format?
I will share the solution to my problem.