Sometimes, we want to subtract one month using moment.js and JavaScript.
In this article, we’ll look at how to subtract one month using moment.js and JavaScript.
How to subtract one month using moment.js and JavaScript?
To subtract one month using moment.js and JavaScript, we can use the subtract
method.
For instance, we write
const d = moment().subtract(1, "months").format("MMM YYYY");
to create a moment object with the current datetime with moment
.
Then we call subtract
with 1 and 'months'
to subtract 1 month from the current date time in the moment object and return it.
And then we call format
to return a formatted date string with the month and year.
Conclusion
To subtract one month using moment.js and JavaScript, we can use the subtract
method.