Created
December 26, 2016 09:54
-
-
Save baladkb/1bc0a2e1af9e2a9ae74a070d3280bb94 to your computer and use it in GitHub Desktop.
Get in-between dates via start and end date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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