Categories
JavaScript Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *