- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
To get the yesterday date, first of all get the current date and subtract 1 from the current and use the function setDate(). The syntax is as follows −
yourCurrentDateVariableName.setDate(yourCurrentDateVariableName.getDate() - 1);
At first, get the current date −
var currentDate = new Date();
Now, get yesterday’s date with the following code −
var currentDate = new Date(); console.log("The current date="+currentDate); var yesterdayDate = currentDate.setDate(currentDate.getDate()- 1); console.log("The yesterday date ="+new Date(yesterdayDate));
To run the above program, you need to use the following command −
Here, my file name is demo137.js. This will produce the following output −
- How to select yesterday's date in MySQL?
- Find yesterday’s, today’s and tomorrow’s date in Python
- How to get today's date in Java8?
- How to get yesterday records from timestamp in Android sqlite?
- Get all MySQL records from the previous day (yesterday)?
- How to get the certificate's start and expiry date using PowerShell?