ToTa ToTa - 1 year ago 94
Javascript Question

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))


But how do I achieve this with MomentJs ?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download