[英]converting string date (without separator) to date format in scala
i have some issues to convert a column with Dates.我在转换带有日期的列时遇到了一些问题。 my date column Looks like this "20032016" "ddMMyyyy".
我的日期列看起来像这样“20032016”“ddMMyyyy”。 When i convert it, i get only null.
当我转换它时,我只得到空值。 I used following code:
我使用了以下代码:
df.withColumn("reporting_date",date_format(to_date(col("reporting_date"), "ddMMyyyy"), "yyyy-MM-dd")).show
does someone can help me?有人可以帮助我吗?
Your code example works for me:您的代码示例对我有用:
scala> val df = Seq("20032016").toDF
df: org.apache.spark.sql.DataFrame = [value: string]
scala> df.withColumn("reporting_date",date_format(to_date(col("value"), "ddMMyyyy"), "yyyy-MM-dd")).show
+--------+--------------+
| value|reporting_date|
+--------+--------------+
|20032016| 2016-03-20|
+--------+--------------+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.