How to get yesterday’s date with moment.js and JavaScript?

Sometimes, we want to get yesterday’s date with moment.js and JavaScript.

In this article, we’ll look at how to get yesterday’s date with moment.js and JavaScript.

How to get yesterday’s date with moment.js and JavaScript?

To get yesterday’s date with moment.js and JavaScript, we call the subtract method.

For instance, we write

const yesterday = moment().subtract(1, "days");

to call moment to create a moment object with the current date.

And then we call subtract with 1 and 'days' to return a moment object that subtracts the current date by 1 day.

Conclusion

To get yesterday’s date with moment.js and JavaScript, we call the subtract method.