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 :: vue component lifecycle 
Javascript :: how the concat function works javascript 
Javascript :: add color to attribute using jquery 
Javascript :: convert % to px javascript 
Javascript :: dull or blur a background image in react native 
Javascript :: js how to see console day tomorrow 
Javascript :: json parse in javascript 
Javascript :: adding a if stement in jsx 
Javascript :: js environment variables 
Javascript :: postman environment variables 
Javascript :: mysql_real_escape_string for nodejs 
Javascript :: How to end a session in ExpressJS 
Javascript :: math captcha 
Javascript :: ajax file upload input 
Javascript :: function to count words in string 
Javascript :: how to check empty object js 
Javascript :: jquery works until modal is shown 
Javascript :: javascript add to home screen button 
Javascript :: remove duplicate values from array 
Javascript :: how to create two dimensional array in js 
Javascript :: selected text 
Javascript :: obfuscation js 
Javascript :: js dictionary 
Javascript :: model export in node js 
Javascript :: query string to object javascript 
Javascript :: get textarea value jquery 
Javascript :: axios delete request 
Javascript :: node server index.html 
Javascript :: prevent form submit html javascript jquery 
Javascript :: clone a JavaScript object 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =