If you are seeking a JavaScript function to calculate the difference between two dates in minutes, you have come to the right place. Here is a simple JavaScript code.
function GetdiffinMinute()
{
var d1 = new Date("12/04/2020")
var d2 = new Date("11/04/2020")
var diff = (d1.getTime() - d2.getTime()) / 60000;
var mintdiff = Math.abs(Math.round(diff));
return mintdiff
}
Subtracting two Date objects gives you the result in milliseconds. If you want the result in minutes, divide the result by 1000 to get the number of seconds. Then, divide that value by 60 to get the number of minutes. So, you can say that dividing the value by 60000 gives you the difference in minutes.
Using the above concept, you can also write a generic JavaScript function which will return the difference between two dates in minutes, hours, days, and milliseconds."
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button onclick="GetdiffinMinute()" type="button">Click</button>
<script type="text/javascript">
function GetdiffinMinute()
{
var todaydate = new Date();
var Newyearday = new Date("2020-01-01");
var diffMs = (todaydate - Newyearday); //diffrence in milliseconds between now & Christmas
var diffDays = Math.floor(diffMs / 86400000); //diffrence in days
var diffHrs = Math.floor((diffMs % 86400000) / 3600000); //diffrence in hours
var diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); //diffrence in minutes
alert(diffDays + " days, " + diffHrs + " hours, " + diffMins + " minutes until Christmas 2009 =)");
}
</script>
</body>
</html>