0

Below code not working with "moment": "^2.19.1",

var a = moment([2017, 12, 09]);
var b = moment([2011, 02, 17]);

var years = a.diff(b, 'year');
b.add(years, 'years');

var months = a.diff(b, 'months');
b.add(months, 'months');

var days = a.diff(b, 'days');
console.log(years + ' years ' + months + ' months ' + days + ' days');

Please help.

Chandresh
  • 277
  • 2
  • 14

1 Answers1

1

You can use moment duration format.

Include moment duration format plugin, and then..

var duration = moment.duration(a.diff(b));
console.log(duration.format('y [years] m [months] d [days]'));
emil
  • 6,074
  • 4
  • 30
  • 38