We are designing online licensing application
I Need to calculate the no of days between the date of event and the date applied The date of event are Sept 16th and Dec 31st.
Java script to count number of days
We are designing online licensing application
I Need to calculate the no of days between the date of event and the date applied The date of event are Sept 16th and Dec 31st.
Java script to count number of days
With using the Javascript Date Object you can use the following function:
var firstDate = new Date("October 16, 1975 11:13:00");
var secondDate = new Date("October 14, 1975 11:13:00");
function dateDifference(start, end)
{
return Math.round((start-end)/(1000*60*60*24));
}
alert(dateDifference(firstDate.getTime(), secondDate.getTime()));
Another approach is comparing dates until they're the same. Probably a lot slower, so don't use this unless you want to extend the comparison with extra details.
fiddle: http://jsfiddle.net/rudiedirkx/Szvfd/
Date.prototype.getYMD = function() {
return this.getFullYear() + '-' + (this.getMonth()+1) + '-' + this.getDate();
};
Date.prototype.getDaysDiff = function(d2) {
var d1 = this,
delta = d1 < d2 ? +1 : -1;
var days = 0;
while (d1.getYMD() != d2.getYMD()) {
days++;
d1.setDate(d1.getDate() + delta);
}
return delta * days;
}
d1 = new Date('October 16 2012');
d2 = new Date('November 7 2012');
console.log(d1.getDaysDiff(d2)); // 22
console.log(d2.getDaysDiff(d1)); // -22