title: How to handle dates in Spark using Scala?
body: <p>I have a flat file that looks like as mentioned below.</p>
  
  <pre><code>id,name,desg,tdate
  1,Alex,Business Manager,2016-01-01
  </code></pre>
  
  <p>I am using the Spark Context to read this file as follows.</p>
  
  <pre><code>val myFile = sc.textFile("file.txt")
  </code></pre>
  
  <p>I want to generate a Spark DataFrame from this file and I am using the following code to do so.</p>
  
  <pre><code>case class Record(id: Int, name: String,desg:String,tdate:String)
  
  val myFile1 = myFile.map(x=&gt;x.split(",")).map {
    case Array(id, name,desg,tdate) =&gt; Record(id.toInt, name,desg,tdate)
  } 
  
  myFile1.toDF()
  </code></pre>
  
  <p>This is giving me a DataFrame with id as int and rest of the columns as String.</p>
  
  <p>I want the last column, tdate, to be casted to date type.</p>
  
  <p>How can I do that?</p>