How to subtract date from today's date in JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

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
raja
Published on 10-Sep-2020 10:50:02
Advertisements