Skip to content

Instantly share code, notes, and snippets.

@baladkb
Created December 26, 2016 09:54
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 baladkb/1bc0a2e1af9e2a9ae74a070d3280bb94 to your computer and use it in GitHub Desktop.
Save baladkb/1bc0a2e1af9e2a9ae74a070d3280bb94 to your computer and use it in GitHub Desktop.
Get in-between dates via start and end date
function formatDate(inputDate) {
var chunks = inputDate.split('/');
var formattedDate = chunks[1]+'/'+chunks[0]+'/'+chunks[2];
return formattedDate;
}
function dateFormat(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;
}
console.log(dateFormat(new Date("mm/dd/yyyy")),new Date(formatDate("mm/dd/yyyy"))));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment