![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to subtract date from today's date in JavaScript?
You need to use currentDate with the help of new Date().getDate(). The syntax is as follows −
var anyVariableName= yourCurrentDate - yourSubstractDateOfCurrentMonth;
Example
var currentDate=new Date().getDate(); var substractDate=new Date("2020-07-01").getDate(); const numberOfDaysInCurrentMonthOnly = currentDate-substractDate; console.log(numberOfDaysInCurrentMonthOnly);
Note
Today’s date is - 28-07-2020
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo129.js
PS C:\Users\Amit\JavaScript-code> node demo129.js 27
Advertisements