Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript date difference in months

function monthDiff(d1, d2) {
    var months;
    months = (d2.getFullYear() - d1.getFullYear()) * 12;
    months -= d1.getMonth();
    months += d2.getMonth();
    return months <= 0 ? 0 : months;
}
Comment

check if the difference between two dates is more than 1 month in javascript

const diffInMonths = (end, start) => {
   var timeDiff = Math.abs(end.getTime() - start.getTime());
   return Math.round(timeDiff / (2e3 * 3600 * 365.25));
}

const result = diffInMonths(new Date(2015, 3, 28), new Date(2015, 1, 25));

// shows month difference as integer/number
console.log(result);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript if statement 
Javascript :: jquery once 
Javascript :: how to get current formatted date dd/mm/yyyy in javascript 
Javascript :: get user agent in js 
Javascript :: selector jquery 
Javascript :: passport jwt npm 
Javascript :: jason in javascript 
Javascript :: useScroll 
Javascript :: set selected value of dropdown using formcontrol in angular 
Javascript :: fetch json data into array 
Javascript :: google jquery 3.5.1 
Javascript :: foreach in react 
Javascript :: js create object with keys 
Javascript :: fontawesome icon size 1.5 angular 
Javascript :: react native font awesome 
Javascript :: javascript next friday 
Javascript :: javascript Using splice() to Remove Elements 
Javascript :: hasownproperty javascript 
Javascript :: remove falsy values from array with lodash 
Javascript :: context api react 
Javascript :: javascript intl.numberformat percent 
Javascript :: js socket.emit 
Javascript :: get all data attributes jquery from multiple elements 
Javascript :: add even numbers recursion js 
Javascript :: projection in mongodb 
Javascript :: javascript how to remove the last character of the string 
Javascript :: today date selected in datepicker 
Javascript :: compare object array equals 
Javascript :: animate javascript 
Javascript :: es6 array to object keys 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =