Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.diff() returns negative value #4287

Closed
ninigix opened this issue Nov 2, 2017 · 3 comments
Closed

.diff() returns negative value #4287

ninigix opened this issue Nov 2, 2017 · 3 comments

Comments

@ninigix
Copy link

ninigix commented Nov 2, 2017

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.

@sprycoder
Copy link

This is achievable through another way.

moment.duration(moment('2016-02-01').diff(moment('2016-03-01'))).asDays()

@ashsearle
Copy link
Contributor

@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')

@icambron
Copy link
Member

What @ashsearle said. I would take the Math.abs() of the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants