You are currently viewing Spark to_date() – Convert String to Date format

In this tutorial, we will show you a Spark SQL example of how to convert String to Date format using  to_date() function on the DataFrame column with Scala example.

Note that Spark Date Functions support all Java Date formats specified in DateTimeFormatter.

to_date() – function is used to format string (StringType) to date (DateType) column.

Syntax: to_date(dateColumn:Column,format:String) : Column 

Below code, snippet takes the date in a string and converts it to date format on DataFrame.



|      Date|   to_date|

Complete Example

package com.sparkbyexamples.spark.dataframe.functions.datetime

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.{col, to_date}

object StringToDate extends App {

  val spark:SparkSession = SparkSession.builder()

  import spark.sqlContext.implicits._



In this article, you have learned how to convert String to Date format using Date functions.

Naveen Nelamali

Naveen Nelamali (NNK) is a Data Engineer with 20+ years of experience in transforming data into actionable insights. Over the years, He has honed his expertise in designing, implementing, and maintaining data pipelines with frameworks like Apache Spark, PySpark, Pandas, R, Hive and Machine Learning. Naveen journey in the field of data engineering has been a continuous learning, innovation, and a strong commitment to data integrity. In this blog, he shares his experiences with the data as he come across. Follow Naveen @ LinkedIn and Medium