Been trying to resolve this one for a while with no success, I found couple of similar answers here, but the format is what is important here. I need to return X years, X months, X days.
Can you take a look to see, what I am doing wrong here... Number of days are not quite right.
Here is a bin
function inBetweenDays(y,m,d){
var user_date = new Date(y,m + 1,d);
var today_date = new Date();
var diff_date = (user_date - today_date);
var num_years = diff_date/31536000000;
var num_months = (diff_date % 31536000000)/2628000000;
var num_days = ((diff_date % 31536000000) % 2628000000)/86400000;
var years = Math.floor(Math.abs(num_years));
var months = Math.floor(Math.abs(num_months));
var days = Math.floor(Math.abs(num_days));
if (years >= 1) {
console.log(years + " years " + months + " months " + days + " days");
} else if (years <= 0 && months >= 0){
console.log(months + " months " + days + " days");
} else {
console.log(days + " days ");
}
}
inBetweenDays(2015,03,04);
inBetweenDays(2016,03,04);
inBetweenDays(2016,02,04);
inBetweenDays(2018,02,04);