Having a really weird issue I can't pinpoint. I've tried a few different variations to get the number of days between two dates in JS. For the most part (99% of the time), the below works great, but I've been getting some incorrect results **sometimes when I cross over months. For example, if I get the amount of days between July 31st, 2015 and August 1st, 2015, it correctly returns 1. However, if I try to grab the amount of days between June 30th, 2015 and July 1st, 2015 I get the result of 2 days (there are only 30 days in June, I've double checked). Is this something with my server environment or am I going crazy?
start_date = new Date(start); // assuming the format is correct
end_date = new Date(ends); // assuming the format is correct
diff_ms = end_date.getTime() - start_date.getTime();
var days = diff_ms / 86400000;
I've also tried the following and got the exact same results:
start_date = new Date(start); // assuming the format is correct
end_date = new Date(ends); // assuming the format is correct
var timeDiff = Math.abs(end_date.getTime() - start_date.getTime());
var days = Math.ceil(timeDiff / (1000 * 3600 * 24));