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.