Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Moment.js, why doesn't subtract by 'week' work?

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.

like image 665
Dave Fontenot Avatar asked Dec 18 '13 17:12

Dave Fontenot


1 Answers

You have it backwards from the Moment API.

moment().subtract(1, 'week');
like image 102
jemiloii Avatar answered Nov 19 '22 11:11

jemiloii