I am working on a small webapp for calculating the count of days.
What i've figured out is:
function cost() {
var oneDay = 24*60*60*1000; //hours*minutes*seconds*milliseconds
var firstDate = new Date(2008,01,12); //Would like to input it myself
var secondDate = new Date(2008,01,22); //Would like to input it myself
var diffDays = Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay));
var priceInDays = diffDays * 250;
alert(priceInDays);
}
What I would like instead is to set the dates dynamically. I am using the Chrome date picker what will return the date as: 2017-03-30. I've tried something like this:
var firstDate = document.getElementById('dateRent').value;
var secondDate = document.getElementById('dateEnd').value;
But that didn't work out. So now, the dates are set the hard coded way. It will give me 10 * 250 = 2500 in the alert box.
I've created a jsfiddle (one problem, it doesn't handle my function, can't find the problem. https://jsfiddle.net/w93c571x/3/