For instance, I have start
and end
start = new Date(2013, 2, 28)
end = new Date(2013, 3, 2)
How could I get from this an array like this
[new Date(2013, 2, 28),
new Date(2013, 2, 29),
new Date(2013, 2, 30),
new Date(2013, 2, 31),
new Date(2013, 3, 1),
new Date(2013, 3, 2)]
I'm currently reading docs about Time-Scales but still having trouble in understanding how to use them for achieving this effect. (Or, maybe there is a better way to do this, if so, I'd be happy to know)
For instance, I have start
and end
start = new Date(2013, 2, 28)
end = new Date(2013, 3, 2)
How could I get from this an array like this
[new Date(2013, 2, 28),
new Date(2013, 2, 29),
new Date(2013, 2, 30),
new Date(2013, 2, 31),
new Date(2013, 3, 1),
new Date(2013, 3, 2)]
I'm currently reading docs about Time-Scales but still having trouble in understanding how to use them for achieving this effect. (Or, maybe there is a better way to do this, if so, I'd be happy to know)
Share Improve this question asked Jun 22, 2013 at 0:08 evfwcqcgevfwcqcg 16.3k15 gold badges57 silver badges72 bronze badges3 Answers
Reset to default 8To update this answer for the d3 V4 syntax, use:
var dateRange = d3.timeDays(new Date(2013, 2, 28), new Date(2013, 3, 2));
Some important notes:
- The month is 0-indexed, so 0 is January. This example will start on March 28th, not February 28th.
- The end date is not included in the return value. Thus the last date in the this example is the 1st, not the 2nd.
Just found out that I can use range
with Time Intervals
d3.time.day.range(new Date(2013, 2, 28),
new Date(2013, 3, 2 + 1))
To do it with d3:
var dateArray = d3.time.scale()
.domain([new Date(2013, 2, 28), new Date(2013, 3, 2)])
.ticks(d3.time.days, 1)
Online demo: http://jsfiddle/aczuV/1/