How To Calculate Number Of Days Between Two Dates Using jQuery

AuthorSumit Dey Sarkar

Pubish Date23 Aug 2022

categoryJQuery

In this tutorial we will learn how to calculate number of days between two dates using jQuery.

lets's see the example - 

How to calculate number of days between two dates using jQuery

<!DOCTYPE html>
<html>
<head>
    <title>How to calculate number of days between two dates using jQuery</title>
</head>
<body>
  
<script type="text/javascript">
   
var allDays = DatesForDifference('08/23/2022', '08/30/2022');
  
console.log(allDays);
  
function DatesForDifference(firstDate, secondDate){
    var startingDay = new Date(firstDate);
    var endingDay = new Date(secondDate);
   
    var millisBetween = startingDay.getTime() - endingDay.getTime();
    var allDays = millisBetween / (1000 * 3600 * 24);
   var totalDays= Math.round(Math.abs(allDays));
   alert('total days = ' + totalDays) ;
}
</script>
   
</body>
</html>

 

Output

jQuery

Comments 0

Leave a comment