Getting Yesterday’s date
First, we need to access the today’s date using
new Date() constructor then we need to subtract it with
const today = new Date(); // it gives yesterday date today.setDate(today.getDate()-1); console.log(today.toDateString()); // Thu Apr 02 2020
In the above code, we used the
setDate() method on
today and passed
today's date minus 1 as arguments to get yesterday’s date.