How to format date and subtract days using Moment.js and JavaScript?

Sometimes, we want to format date and subtract days using Moment.js and JavaScript.

In this article, we’ll look at how to format date and subtract days using Moment.js and JavaScript.

How to format date and subtract days using Moment.js and JavaScript?

To format date and subtract days using Moment.js and JavaScript, we call format to format dates and subtract to subtract days.

For instance, we write

let startdate = moment();
startdate = startdate.subtract(1, "days");
startdate = startdate.format("DD-MM-YYYY");

to call subtract to subtract 1 day from the current date.

And then we call format to return a date string in DD-MM-YYYY format.

Conclusion

To format date and subtract days using Moment.js and JavaScript, we call format to format dates and subtract to subtract days.