How to get yesterday's date 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()