Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // Returns an array of dates between the two dates
  2. var getDates = function(startDate, endDate) {
  3. var dates = [],
  4. currentDate = startDate,
  5. addDays = function(days) {
  6. var date = new Date(this.valueOf());
  7. date.setDate(date.getDate() + days);
  8. return date;
  9. };
  10. while (currentDate <= endDate) {
  11. dates.push(currentDate);
  12. currentDate = addDays.call(currentDate, 1);
  13. }
  14. return dates;
  15. };
  16.  
  17. // Usage
  18. var dates = getDates(new Date(2013,10,22), new Date(2013,11,25));
  19. dates.forEach(function(date) {
  20. console.log(date);
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement