Jquery Get Difference Between Two Dates In Days Example

Jquery

Nicesnippets

353

25-06-2021


Hi Guys,

In this exmple,I will learn you how to get difference between two dates in days.you can easy and simply get difference between two dates in days.

You have to just follow this example for getting number of days between two dates in jquery.

Example:


<!DOCTYPE html>

<html>

<head>

<title>Jquery get difference between two dates in days example - Nicesnippets.com</title>

</head>

<body>

<script type="text/javascript">

var days = daysdifference('6/15/2021','6/20/2021');

console.log(days);

function daysdifference(firstDate, secondDate){

var startDay = new Date(firstDate);

var endDay = new Date(secondDate);

var millisBetween = startDay.getTime() - endDay.getTime();

var days = millisBetween / (1000 * 3600 * 24);

return Math.round(Math.abs(days));

}

</script>

</body>

</html>

Output:

5

It will help you...