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

moment().diff returns negative value #255

Closed
btmdave opened this issue Apr 4, 2012 · 1 comment
Closed

moment().diff returns negative value #255

btmdave opened this issue Apr 4, 2012 · 1 comment
Labels

Comments

@btmdave
Copy link

btmdave commented Apr 4, 2012

//Wed, 04 Apr 2012 21:09:16 GMT to = moment.utc().add('m', 60).toDate(); seconds = moment.diff(to, 'seconds');
I'm trying to get the seconds from the current time in UTC and another date that is set in UTC.

I'm using moment.diff- the above code returns a negative value of -3600 instead of 3600.

Is this the correct way to do this? Shouldn't the negative only be if the date has passed?

@timrwood
Copy link
Member

timrwood commented Apr 6, 2012

That should be clarified in the docs.

If the moment is earlier than the one you are diffing, it should be negative. If it is after the one you are diffing, it will be positive.

Think of it this way...

var a = moment(),
    b = moment().add('hours', 1);
a.diff(b); // a - b
b.diff(a); // b - a

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

No branches or pull requests

2 participants