Accepted answer

In D3 3.5, you could parse just the way you did, setting the time format...

var formatDate = d3.time.format("%d-%b-%y");

...and then using this time format to parse: = formatDate.parse(;

But, using D3 4.0, you have to parse dates in a different way, using timeParse:

var parseTime = d3.timeParse("%d-%b-%y");

And, then, modifying your accessor function:

function type(d) { = parseTime(;
  d.Flux = +d.Flux;
  return d;


The api has changed. For me the solution was:

var parseTime = d3.timeParse("%Y-%m")
=> Sat Sep 01 2018 00:00:00 GMT-0400 (Eastern Daylight Time)

If you want to go the other way, Date class to string:

var formatTime = d3.timeFormat("%Y-%m")
formatTime(new Date)
=> "2020-09"

Related Query

More Query from same tag