I need help calculating the number of months and remaining days between two dates.
For example:
start = 2017-04-10, end = 2017-05-15
The desired output should be 1 month, 5 days
-
This is my approach: Calculating number of months:
var numOfMonths = end_month - start_month + (12 * (end_year - start_year));
if(end_day < start_day){
numOfMonths--;
}
And for the days:
var numOfDays = (end - start) / (1000 * 60 * 60 * 24)
The current output shows as 1 month, 35 days.
How can I adjust the calculation to remove the days associated with a full month, and only display the remaining days?