title: I want to convert string to Date using SqlContext
body: <pre><code>df = sqlContext.read.option(&quot;header&quot;, &quot;true&quot;).csv(&quot;baby_names.csv&quot;)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/iRhlu.png" rel="nofollow noreferrer">df.show(5)</a></p>
  <p><a href="https://i.stack.imgur.com/8pQBv.png" rel="nofollow noreferrer">df.printSchema()</a></p>
  <p>I want to convert a string to a date and get only the year.</p>
  <p>I try -</p>
  <pre><code>df=df.withColumn(&quot;Year&quot;,col(&quot;Year&quot;).cast(DateType()))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/KbbmZ.png" rel="nofollow noreferrer">But that's what I got</a></p>
  <p>I want to get, for example only 2013</p>