How to get yesterday's date with Momentjs?

So, my question is simple, how do I get yesterday's date with MomentJs ? In Javascript it is very simple, i.e.

today = new Date();
yesterday = new Date(today.setDate(today.getDate() - 1))

console.log(yesterday)

But how do I achieve this with MomentJs ?


Just like this: moment().subtract(1, 'days'). It will give you the previous day with the same exact current time that is on your local pc.


Also :

moment().subtract(1, 'day')

It will give you the previous day with the same exact current time that is on your local pc.


When we get yesterday's date, there are three possibilties

1. Get yesterday date with current timing

moment().subtract(1, 'days').toString()

2. Get yesterday date with start of the day

moment().subtract(1, 'days').startOf('day').toString()      

3. Get yesterday date with end of the day

moment().subtract(1, 'days').endOf('day').toString()

moment().add(-1, 'days');

You can find more information in the docs.


You can easily subtract days from moment using

var yesterday = moment().subtract(1, 'days')

And for finding the previous date

var previousDay = moment('2017/11/6', 'YYYY/MM/DD').subtract(1, 'days')