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

Wrong result in date diff in days #6211

Open
babu-zolve opened this issue Feb 23, 2024 · 1 comment
Open

Wrong result in date diff in days #6211

babu-zolve opened this issue Feb 23, 2024 · 1 comment

Comments

@babu-zolve
Copy link

example 1:
var a = moment([2024, 2, 23]);
var b = moment([2023, 2, 24]);
console.log(a.diff(b, 'days') );
Output : 365
example 2:
var a = moment([2024, 2, 24]);
var b = moment([2024, 2, 23]);
console.log(a.diff(b, 'days') );
Output : 1

As we see in example 2, this is not including the both dates for diff in term of days. So ideally in first example, it should give 364(5+31+30+31+30+31+31+30+31+30+31+31+22) days.

@utf26
Copy link

utf26 commented Mar 21, 2024

months are 0-indexed in moment.js (0 = January, 1 = February, etc.)

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

2 participants