Difference Between two Dates using JQuery or Javascript?
Here code use difference between two dates.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script>
$(document).ready(function(){
var $datepicker1 = $( "#datepicker1" );
var $datepicker2 = $( "#datepicker2" );
$datepicker1.datepicker();
$datepicker2.datepicker({
onClose: function() {
var fromDate = $datepicker1.datepicker('getDate');
var toDate = $datepicker2.datepicker('getDate');
var diff = new Date(toDate - fromDate);
var days = diff/1000/60/60/24;
alert(days);
}
});
});
</script>
</head>
<body>
<h2>Difference between the dates</h2>
<p>From Date: <input type="text" id="datepicker1"></p>
<p>To Date: <input type="text" id="datepicker2"></p>
</body>
</html>
Comments
Post a Comment