Reputation: 89
After using this function to get the number of days I want to get the names of days between two dates ionic+angularjs.
$scope.dayDiff = function (date1, date2) {
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
$scope.dayDifference = Math.ceil(timeDiff / (1000 * 3600 * 24));
alert($scope.dayDifference);
}
Upvotes: 2
Views: 819
Reputation: 4900
Here's how I did it. View Plunkr Demo
angular.module('app', [])
.controller('MainCtrl', function($scope) {
var days = function(date1, date2) {
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diff = Math.ceil(timeDiff / (1000 * 3600 * 24));
var _days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var days = [];
for (var i = 0; i < diff; i++) {
date1.setDate(date1.getDate() + i);
days.push(_days[date1.getDay()]);
}
return days;
};
$scope.days = days(new Date(2016, 05, 01), new Date(2016, 05, 05));
})
Upvotes: 3