Issue with scala date conversion


#1

I have order table imported on HDFS in avro file format.I read that data to convert into dataframe
Now I have issue with order_date which is string and want to convert it into date format.I need help in scala.I solved this problem with sql query using spaContext.sql.I want to solve it with data frame in scala.Please help


#2

Hi @jyoti

You can use the date_format function.
Sample Example I can give you

import sqlContext.implicits._
import org.apache.spark.sql.functions._

  val df = sc.parallelize(Array(
    ("hello", "2000-02-02", "2010-10-10", 200),
    ("welcome", "2010-11-12", "2011-08-03", 270),
    ("itversity", "2018-2-06", "2018-05-03", 150))).toDF("name", "startDate", "endDate", "price")

  df.show()

  df.select(date_format(col("endDate"), "MM/dd/yyyy")).show

#4

Thanks sunil_abhishek …:grinning::grinning: