Find the month difference between two different dates in Javascript

Here is the approach:

  1. Subtract the year values from both the dates and multiply the result by 12.
  2. Subtract the month values from both the dates
  3. Subtract the day values from both the dates and divide the result by 30
  4. Add all the above values, the integer part of it as the answer.


var startdate = new Date('2011-05-01');
var enddate = new Date('2021-04-01');
var MonthDifference =
//Difference in years, multiplied by 12.
((enddate.getFullYear() - startdate.getFullYear()) * 12) +
//Difference in months.
(enddate.getMonth() - startdate.getMonth()) +
//integer value of( Difference in days, divided by 30.
Math.floor((enddate.getDate() - startdate.getDate()) / 30);

1. Math.floor() function is used to round a number downward to its nearest integer value.
2. The above method does not return the exact month difference. It only returns the completed months value.
3. Online tool for calculating the same can be found at here.


Edge browser specific CSS styling

Below code can be used to apply CSS styling which is specific to Edge browser. This can be used to fix any edge browser related issues.

/* red color is applied to this id in all other browsers.*/
#text {
/* green color is applied to the text id in edge browser.*/
@supports (-ms-ime-align: auto) {
   #text {