Sometimes, we want to get month name of last month using moment and JavaScript.
In this article, we’ll look at how to get month name of last month using moment and JavaScript.
How to get month name of last month using moment and JavaScript?
To get month name of last month using moment and JavaScript, we use the format
method.
For instance, we write
const monthMinusOneName = moment()
.subtract(1, "month")
.startOf("month")
.format("MMMM");
to call subtract
to subtract 1 month from today’s date.
We call startOf
to return the start date of the month.
And we call format
with 'MMMM'
to return the month name.
Conclusion
To get month name of last month using moment and JavaScript, we use the format
method.