Good day, I want to calculate the remaining days between the expiration date and the current date but it seems that the return is not what I expected.
function expiryDate(date_string) {
var date = date_string.split("/");
var year = parseInt(date[2]);
var day = parseInt(date[1]);
var month = parseInt(date[0]);
var expiration = new Date(month,day,year);
var d = new Date();
var curr_day = d.getDate();
var curr_month = d.getMonth()+1;
var curr_year = d.getFullYear();
var current_date = new Date(curr_month, curr_day, curr_year);
return (expiration - current_date) / (1000*60*60*24);
}
the code above will return the correct remaining days if the dates are the same for example.. the current date string was 05/01/2018 and the expiration is also the same and it will return 0, but when i move the expiration date to 1 day like 05/02/2018 the return is 28 days which is not correct.
How can I fix this problem?