I am trying to figure out the exact number of months and days between two specific dates.
For example, if the start date is "Jan 12, 2014" and the end date is "Mar 27, 2017", the result should be "38 months and 15 days".
However, I am currently only able to calculate the total number of days between the start and end dates. I need assistance in determining the months and days in between.
Additionally, I would like to know how to divide the 15 days by the total number of days in the end-date month.
If anyone could provide some guidance, I would greatly appreciate it as I am new to working with date functions.
var date = new Date();
console.log("date: "+date);
var currentDate = $filter('date')(date, "yyyy-MM-dd HH:mm:ss");
$scope.userdob = "2017-01-29";
var dobdate = $filter('date')($scope.userdob, "yyyy-MM-dd HH:mm:ss");
console.log("dob: "+dobdate);
/* differentiate Date */
var date1 = $filter('date')($scope.userdob, "yyyy-MM-dd");
var date2 = $filter('date')(date, "yyyy-MM-dd");
date1 = date1.split('-');
date2 = date2.split('-');
date1 = new Date(date1[0], date1[1], date1[2]);
date2 = new Date(date2[0], date2[1], date2[2]);
var date1_unixtime = parseInt(date1.getTime() / 1000);
var date2_unixtime = parseInt(date2.getTime() / 1000);
var timeDifference = date2_unixtime - date1_unixtime;
var timeDifferenceInHours = timeDifference / 60 / 60;
$scope.timeDifferenceInDays = timeDifferenceInHours / 24;
console.log("timeDifferenceInDays: "+$scope.timeDifferenceInDays);