Skip to content

Instantly share code, notes, and snippets.

@kfox
Created August 14, 2019 23:18
Show Gist options
  • Save kfox/5bea080772c3d45dd00a806f5bb4d3cd to your computer and use it in GitHub Desktop.
Save kfox/5bea080772c3d45dd00a806f5bb4d3cd to your computer and use it in GitHub Desktop.
Date range using moment.js
// startDate and endDate are moment() dates
// returns an array of dates in the given format
const getDateRange = (startDate, endDate, { format = 'YYYY-MM-DD' } = {}) => {
const date = startDate.clone()
const dates = []
while (date.isSameOrBefore(endDate)) {
dates.push(date.format(format))
date.add(1, 'days')
}
return dates
}
export { getDateRange }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment