programming-examples/js/Date/Write a JavaScript function to get time differences in months between two dates..js

16 lines
428 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function diff_months(dt2, dt1)
{
var diff =(dt2.getTime() - dt1.getTime()) / 1000;
diff /= (60 * 60 * 24 * 7 * 4);
return Math.abs(Math.round(diff));
}
dt1 = new Date(2014,10,2);
dt2 = new Date(2014,10,11);
console.log(diff_months(dt1, dt2));
dt1 = new Date("June 13, 2014 08:11:00");
dt2 = new Date("October 19, 2014 11:13:00");
console.log(diff_months(dt1, dt2));