SHARE
TWEET

getDateBetween

Hector2244 Jun 24th, 2019 54 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. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top