var range = getDates(new Date(), new Date().addDays(7));
I'd like "range" to be an array of date objects, one for each day between the two dates.
The trick is that it should handle month and year boundaries as well.
Thanks.
var range = getDates(new Date(), new Date().addDays(7));
I'd like "range" to be an array of date objects, one for each day between the two dates.
The trick is that it should handle month and year boundaries as well.
Thanks.
This may help someone,
https://gist.github.com/pranid/3c78f36253cbbc6a41a859c5d718f362.js
I use moment.js and Twix.js they provide a very great support for date and time manpulation
I have this running on http://jsfiddle.net/Lkzg1bxb/
I looked all the ones above. Ended up writing myself. You do not need momentjs for this. A native for loop is enough and makes most sense because a for loop exists to count values in a range.
One Liner:
Long Version
List dates in between:
Days from a past date until now:
If you are using moment then you can use their "official plugin" for ranges
moment-range
and then this becomes trivial.moment-range node example:
moment-range browser example:
date fns example:
If you are using
date-fns
theneachDay
is your friend and you get by far the shortest and most concise answer:Using ES6 you have Array.from meaning you can write a really elegant function, that allows for dynamic Intervals (hours, days, months).