I'd like to know how I can work out the calendar days between 2 dates. Currently I'm converting to timestamps and working out the diff as this seems to be the most common solution as below:
let time = 1561978969653;
let now = new Date();
let uploadDate = new Date(time);
let timeDiff = Math.abs(now.getTime() - uploadDate.getTime());
let days = Math.ceil(timeDiff / (1000 * 3600 * 24));
console.log(timeDiff, days);
However this has certain drawbacks. For example 26/01/2019 @ 11:59:59
to 27/01/2019 00:00:00
should count as 1 calendar day apart, however with the method I'm using it counts as 0 because it didn't have a full 24 hours between the 2 timestamps.
I have also thought about looping through the days and incrementing a counter but that seems a little inefficient and/or inelegant.
Edit: I do not want to implement a 3rd party library for this, I'd like a programatic solution, likewise timestamp based approaches do not resolve the issue of short date intervals as stated in the question above.