You should be able to simplify your function a bit. Refer to this SO post: Get difference between 2 dates in javascript?
var _MS_PER_DAY = 1000 * 60 * 60 * 24;
var dt1 = new Date($scope.myitems.date1);
var dt2 = new Date($scope.myitems.date2);
dateDiffInDays(dt1, dt2);
// a and b are javascript Date objects
function dateDiffInDays(a, b) {
// Discard the time and time-zone information.
var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}
This is a good solution as it ignores Daylight Savings Time & finds the actual difference in time.
Another option: (useful if your string date isn't evaluating properly use new Date()
var _MS_PER_DAY = 1000 * 60 * 60 * 24;
dateDiffInDays('01/02/2014','01/02/2013');
// a and b are assumed to be in the format '01/02/2014'
function dateDiffInDays(a, b) {
// Discard the time and time-zone information.
var dt1 = Date.parse(a + ' UTC'); //appending 'UTC' within Date.parse() will return the # of MS in UTC
var dt2 = Date.parse(b + ' UTC');
return Math.floor((dt2 - dt1) / _MS_PER_DAY); // return -365
}