Uncaught TypeError: date2.diff is not a function (problem 1)
See original GitHub issueThe bug I have the function used in litepicker like this: nights.value = date2.diff(date1, ‘day’); This worked in version 1.0.18 I updated litepicker to the newest 1.4.6 and this suddenly stopped working.
To Reproduce
const picker = new Litepicker({
singleMode: false,
onSelect: function (date1, date2) {
nights.value = date2.diff(date1, 'day');
}
});
Expected behavior This should give back the days in numbers.
jsfiddle.net / codepen.io / etc https://codepen.io/kevinmu/pen/PoZNXzB
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Diff is not a function in Moment.js - javascript - Stack Overflow
The diff function is only available on moment objects. Try this instead: var now = moment(new Date()), end = moment(fd), days = end.diff(now ......
Read more >Problem with the diff() function · Issue #723 · moment ... - GitHub
I try for example this code : moment('2012-02-03').diff(moment('2012-02-06'), 'd') it gives me 0, but the answer should be 3... am I not ......
Read more >Moment.js moment().diff() Function - GeeksforGeeks
diff () function is used to get the difference in milliseconds of given dates which are passed as parameter to this function. Syntax:...
Read more >[Solved]-.diff is not a function in Moment.js-moment.js
Via the docs, moment().format() returns a String, so your x and y variables are both Strings. If you need to both do calculations...
Read more >TypeError: getFullYear() is not a Function in JavaScript
To solve the "getFullYear is not a function" error, make sure to only call the getFullYear() method on a valid Date object, e.g....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I thought so yes, but there is a piece of code within this current version of litepicker using the same code 😃 https://github.com/wakirin/Litepicker/blob/13b64c52cbb999a282f9863a92736a1f76915b69/src/litepicker.ts#L636
This is why I thought something was broken. But your solution is working perfectly, thanks!
I don’t see .diff() as a function of a date object in JavaScript.
I’d have to look, but isn’t that a component of moment.js? I believe that Moment.js was a dependency of the deprecated lightpick picker (that litepicker replaced), but not this picker.
In any case, getting the days difference between two dates can be achieved by: