
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- How to subtract days from a date in JavaScript?
- How to get today's date in Java8?
- How to return today's records using DATE from DATETIME Field?
- How do I subtract minutes from a date in JavaScript?
- Finding the nth day from today - JavaScript (JS Date)
- How do I subtract one week from this date in JavaScript?
- How to subtract Python timedelta from date in Python?
- MySQL query to select closest date from today?
- SELECT MySQL rows where today's date is between two DATE columns?
- Get the Day of the Week from Today's Date in Java
- How to get the date between TODAY and TODAY-7”?
- How to subtract number of days from a date to get the previous date in R?
- How to create JavaScript Date object from date string?
- Java Program to subtract year from current date
- Java Program to subtract week from current date

Advertisements