Calculating Date Difference in Javascript
Here is java script function to calculate the date difference in number of days.
function dateDiff(date1,date2) {
//Date Format YYYY-MM-DD
var startingdate = date1.split("-");
var startingdate=new Date(startingdate[0], startingdate[1], startingdate[2]) ;//Month is 0-11 in JavaScript
var endingdate = date2.split("-");
var endingdate=new Date(endingdate[0], endingdate[1], endingdate[2]) ;//Month is 0-11 in JavaScript
var one_day=1000*60*60*24;
alert("Difference is "+Math.ceil((endingdate.getTime()-startingdate.getTime())/(one_day))+" days ");
}
Points to Remember
- Date Format is YYYY-MM-DD
Labels: date diff javascript, date difference javascript, javascript
posted by adityachandra @ 11:04 PM,
Post a Comment