I am using this below function to calculate number of days between dates. So if date is greater than today’s date then it calculates the number of days from today’s date which seems to be working fine but when the date is less than today’s date and when date is from October it calculates the dates in opposite direction where as it should print Available today. Some examples of date i am facing issue is below like
if date is 2021-10-31 and today’s date is 2021-12-11 then it gives 42 days but it should give Available today
if date is 2021-11-01 and today’s date is 2021-12-11 then it gives Available today
if( currentDish.ServingDateFrom){
if(!isNaN(currentDish.ServingDateFrom)){
if(currentDish.ServingDateFrom.getDate()<=nowDate.getDate()){
availability = "Available Today";
console.log("Available Today");
}else if(currentDish.ServingDateFrom.getDate()>nowDate.getDate()){
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var diffDays = Math.round(Math.abs((currentDish.ServingDateFrom.getTime() - nowDate.getTime()) / (oneDay)));
availability = "Available in " + diffDays + " Days";
console.log(nowDate, " - ", currentDish.ServingDateFrom);
console.log("Available in " + diffDays + " days");
}
}
}