Skip to content

Instantly share code, notes, and snippets.

@psynewave
Created February 1, 2021 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psynewave/9006cd63867d69bfb5c97bf9ed6d620a to your computer and use it in GitHub Desktop.
Save psynewave/9006cd63867d69bfb5c97bf9ed6d620a to your computer and use it in GitHub Desktop.
const getDaysBetweenDates = (dateStart, dateEnd) => (new Date(dateEnd) - new Date(dateStart)) / (1000 * 3600 * 24);
getDaysBetweenDates('1/21/2020', '1/21/2021'); // 366 leap year
getDaysBetweenDates('1/21/2019', '1/20/2020'); // 365
getDaysBetweenDates(new Date('08/04/2020'), new Date('08/24/2020'));
getDaysBetweenDates('08/04/2020','08/24/2020');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment