I'm using Moment.js
and following line of code doesn't seem to actually do anything:
moment().subtract('week', 1)
In the documentation, it shows an example of subtract being used with 'days'
but it doesn't specify that it's the only string you can use. In most of the other functions, it's an option where you can use 'days'
, 'weeks'
, 'months'
, so I'm not sure if I'm doing something wrong or 'weeks'
just isn't supported:
Moment.js Subtract Documentation
Here's the example of subtracting days:
moment().subtract('days', 7);
It's also what I ended up using instead of 'weeks'
but I'm still curious why 'weeks'
aren't supported.
You have it backwards from the Moment API.
moment().subtract(1, 'week');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With