
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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