Edit This Code:
<!DOCTYPE html>
<html>
<body>

<p>Click the button to display the number of years between a specified date and January 1, 1970.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var d = Date.parse("March 21, 2012");
    var minutes = 1000 * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var y = Math.round(d / years);

    document.getElementById("demo").innerHTML = y;
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy