Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Returns an array of dates between the two dates
- var getDates = function(startDate, endDate) {
- var dates = [],
- currentDate = startDate,
- addDays = function(days) {
- var date = new Date(this.valueOf());
- date.setDate(date.getDate() + days);
- return date;
- };
- while (currentDate <= endDate) {
- dates.push(currentDate);
- currentDate = addDays.call(currentDate, 1);
- }
- return dates;
- };
- // Usage
- var dates = getDates(new Date(2013,10,22), new Date(2013,11,25));
- dates.forEach(function(date) {
- console.log(date);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement