Cybernetic
Cybernetic

Reputation: 13334

Parsing month/day/year date format in D3

I am trying to parse the following date format in D3 for line chart visual:

10/29/2015

I have tried:

var formatDate = d3.time.format("%M-%d-%Y");

but it isn't working. Is it possible to parse this format in D3?

Upvotes: 0

Views: 1457

Answers (1)

altocumulus
altocumulus

Reputation: 21578

Your date uses slashes whereas the specifier of your time format has hyphens in it. Defining it as

var formatDate = d3.time.format("%M/%d/%Y");

should do the trick.

console.log(d3.time.format("%M-%d-%Y").parse("10/29/2015"));  // doesn't work
console.log(d3.time.format("%M/%d/%Y").parse("10/29/2015"));  // works
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

Upvotes: 1

Related Questions