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 :: npm install router dom 
Javascript :: import stripe in es6 
Javascript :: window localtion javascript 
Javascript :: how to move an image with arrow keys in javascript 
Javascript :: load script js 
Javascript :: scrolling for chatbot 
Javascript :: javascript replace all spaces with dashes 
Javascript :: javascript random char 
Javascript :: Create slug from string in Javascript 
Javascript :: short date angular pipe 
Javascript :: regular expression replace a dot 
Javascript :: javascript generate random hex 
Javascript :: useswr 
Javascript :: install nodejs ubuntu 19.04 
Javascript :: UnhandledPromiseRejectionWarning: MongoNotConnectedError: 
Javascript :: How to more than one slot in graph node in godot 
Javascript :: react native outside area view color 
Javascript :: remove disabled js 
Javascript :: flexbox stretch height 
Javascript :: disable enter on input field react 
Javascript :: nodejs check directory exist or not 
Javascript :: javascript find link by href 
Javascript :: jquery create element 
Javascript :: externalCodeSetup.navigationApi.replaceScreenComponent 
Javascript :: jquery add inline style 
Javascript :: click on child prevent click on parent 
Javascript :: fill all field of object in js 
Javascript :: how 2 subtract 2 dates using moment.js 
Javascript :: useMutation on success function not being called 
Javascript :: jspdf addimage 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =