Home Javascript Difference between two dates in days in jquery

Difference between two dates in days in jquery

by Shahriar Sagor

Hello Dev today now in this article, i will show you how to get days difference between two dates in jquery. We can easily calculate difference between two dates in days by using jquery using Date and Math. We can simply get difference between two dates by using jquery.

In reality we can’t say that by utilizing jquery we are getting distinction between two dates in days.We will utilize javascript capacities like Date and Math for the ascertain contrast between two date on days months and years formation.

By bellow the example we will create simple function daysdifference() with two arguments first date and last date. Function will returns difference in days. So you can easily copy that use in your jquery and php application.

Now you have see simple example on bellow and also you can easily use it in your jquery code.

<!DOCTYPE html>
<html>
<head>
    <title>Jquery get difference between two dates in days example - Codingspoint.com</title>
</head>
<body>
  
<script type="text/javascript">
   
var days = daysdifference('10/11/2019', '10/20/2019');
  
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>

Also Read : How Laravel Livewire Click Event work?

Output:

9

I hope it can help you… Also you can follow us on Facebook

close

You may also like

Leave a Comment