Reputation: 431
I'm using the moment.js library to plot some values on a graph. I have two buttons called Previous and Next that go one month behind and one month forward from the current date respectively.
Now, the issue that I am facing is with the subtract function - for example, since today is February - the endOf('month')
function moves up to 28 days. Now, if I wish to move a month back to January, I am using the following :
moment().endOf('month').subtract(1,'month'+ 's');
This does move back to January, but the date endOf date is still 28 - and due to this my graph only plots until this day of January.
Is there a way I can check for the month and set in the correct last date as I move behind or forward using the subtract function? Or am I missing out on something?
Here is a simple fiddle - I'm alerting the value after using the moment functions.
Upvotes: 0
Views: 339