Categories
JavaScript Answers

How to get date difference in number of days with Moment.js and JavaScript?

Spread the love

Sometimes, we want to get date difference in number of days with Moment.js and JavaScript.

In this article, we’ll look at how to get date difference in number of days with Moment.js and JavaScript.

How to get date difference in number of days with Moment.js and JavaScript?

To get date difference in number of days with Moment.js and JavaScript, we use the diff method.

For instance, we write

const a = moment([2022, 0, 29]);
const b = moment([2022, 0, 28]);
const diff = a.diff(b, "days");

to call a.diff with b and 'days' to get the difference between a and b in days.

Conclusion

To get date difference in number of days with Moment.js and JavaScript, we use the diff method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.