I need to calculate the difference between two reported dates. I need to know the result in years and months. I used the momentary library in conjunction with angularjs.
By putting the Start date as 06/07/2015 and the date of birth as 06/07/1957, the expected result would be 58 years 0 months and 0 days. But the result was 58 years 0 months and 6 days
The function in JS that does this conversion is as follows:
function converterData(){
var hoje = moment($scope.final, "DD/MM/YYYY");
var dia = moment($scope.nascimento, "DD/MM/YYYY");
var duracao = moment.duration(hoje.valueOf()- dia.valueOf(), 'milliseconds');
$scope.idadeAnos = duracao.years();
$scope.idadeMeses = duracao.months();
$scope.idadeDias = duracao.days();
}
I could not find the error!