JSFiddle - React, Tailwind, and code Playground

by bnson

HTML

<!DOCTYPE html>
<html>
<title>VNLIVES.NET</title>    
<body>
    
<button onclick="myFunction()">Calculate Number Of Months Between Two Dates</button>

<script>

function myFunction() {
    var rs = monthDiff(
        new Date(2008, 10, 4), 
        new Date(2010, 2, 12)  
    );
    
    alert(rs);
    
}

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

</body>
</html>