Advertisement
Hector2244

getDateBetween

Jun 24th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var getDateBetween = (startDate, endDate) => {
  2.     const dates = [];
  3.  
  4.     // Strip hours minutes seconds etc.
  5.     let currentDate = new Date(
  6.         startDate.getFullYear(),
  7.         startDate.getMonth(),
  8.         startDate.getDate()
  9.     );
  10.  
  11.     while (currentDate <= endDate) {
  12.                 var date = {
  13.                         date: currentDate
  14.                 }
  15.         dates.push(date);
  16.  
  17.         currentDate = new Date(
  18.             currentDate.getFullYear(),
  19.             currentDate.getMonth(),
  20.             currentDate.getDate() + 1, // Will increase month if over range
  21.         );
  22.     }
  23.  
  24.     return dates;
  25. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement