12

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.

Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
Dave Fontenot
  • 621
  • 2
  • 7
  • 10

2 Answers2

30

You have it backwards from the Moment API.

moment().subtract(1, 'week');
jemiloii
  • 24,594
  • 7
  • 54
  • 83
0

This is a bit old question but it appears that even back then it was relevant.

Definetely nowadays is even more relevant to consider parse.com moment.js version (1.7.2) to the current moment.js version (2.8.4) and the only API doc that parse.com makes reference to

Check an answer to this in a previous post in Trouble using the Moment module

I would suggest to work always with latest moment.js so you can properly work with the provided documentation (during my search I was not able to find 1.7.2 documentation.. beside you will miss many great features working with the version provided in parse.com.

Add the new version as indicated in the same post in the accepted answer.

Community
  • 1
  • 1
Chasky
  • 60
  • 6