This is my date difference to calculated days code and I have user date format of yy-dd-mm
but I have changed my format to dd-mm-yy
.so I have changed format code, but it is not working properly.
Please can anyone help with this?
<script>
var calculate = function() {
var from = document.getElementById("txtdate").value;
var fromdate = from.slice(3, 5);
fromdate = parseInt(fromdate);
var frommonth = from.slice(0, 2);
frommonth = parseInt(frommonth);
var fromyear = from.slice(6, 10);
fromyear = parseInt(fromyear);
var to = document.getElementById("txtdate1").value;
var todate = to.slice(3, 5);
todate = parseInt(todate);
var tomonth = to.slice(0, 2);
tomonth = parseInt(tomonth);
var toyear = to.slice(6, 10);
toyear = parseInt(toyear);
var oneDay = 24*60*60*1000;
var firstDate = new Date(fromyear,frommonth,fromdate);
var secondDate = new Date(toyear,tomonth,todate);
var diffDays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay))+1);
if (diffDays)
document.getElementById("result").value=diffDays;
}
</script>