Description of the Issue and Steps to Reproduce:
execute moment('2016-02-01').diff('2016-03-01', 'days')
Environment:
react 1.6
Examples: Chrome 49 on OSX, Internet Explorer 10 on Windows 7, Node.JS 4.4.4 on Ubuntu 16.0.4
chrome
Basically, I wanted to calculate days between these two dates and the result is -29
.
This is achievable through another way.
moment.duration(moment('2016-02-01').diff(moment('2016-03-01'))).asDays()
@stackninigi Positive vs negative results from diff let you know which date is earlier / later than the other.
If you wanted a positive result, you should ensure you do later.diff(earlier, ...)
i.e. moment('2016-03-01').diff('2016-02-01', 'days')
What @ashsearle said. I would take the Math.abs()
of the result.
Most helpful comment
@stackninigi Positive vs negative results from diff let you know which date is earlier / later than the other.
If you wanted a positive result, you should ensure you do
later.diff(earlier, ...)
i.e.
moment('2016-03-01').diff('2016-02-01', 'days')