Created
August 14, 2019 23:18
-
-
Save kfox/5bea080772c3d45dd00a806f5bb4d3cd to your computer and use it in GitHub Desktop.
Date range using moment.js
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
// 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