How to get yesterday’s date in JavaScript
In this post we will give you information about How to get yesterday’s date in JavaScript. Hear we will give you detail about How to get yesterday’s date in JavaScriptAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to get the yesterday’s date using JavaScript.
Getting Yesterday’s date
First, we need to access the today’s date using new Date() constructor then we need to subtract it with 1.
const today = new Date();// it gives yesterday datetoday.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.
Note: If today is 1st March, JavaScript can figure out yesterday is 28th February.
Hope this code and post will helped you for implement How to get yesterday’s date in JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs